Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

324
Visualizações
Create a .CSS, .HTML and .JS file using Node JS

I am quite new to Node and hence stuck with this!!

I am trying to write a node script that makes a folder (lizardproject) which has three different files i.e. index.html, app.js, style.css.

Code

const fs = require('fs');
const folderName = process.argv[2] || 'Project'

try {
fs.mkdirSync(folderName);
fs.writeFileSync(`${folderName}/index.html`)
fs.writeFileSync(`${folderName}/app.js`)
fs.writeFileSync(`${folderName}/style.css`)
} catch(e) {
    console.log("Something went wrong!!");
    console.log(e);
}

On execution, the folder is being created.

Execution

hp\nodeintro>node boilerplate.js lizardproject

Result

hp\nodeintro>ls
boilerplate.js   lizardproject  

But the files are not, and this error is being displayed:-

Error

Something went wrong!!
TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
at Object.writeFileSync

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Look at the documentation for that function:

fs.writeFileSync(file, data[, options])

file <string> | <Buffer> | <URL> | <integer> filename or file descriptor
data <string> | <Buffer> | <TypedArray> | <DataView> | <Object>

data is the second argument.

You aren't providing the second argument so it is undefined. Hence the error message: Received undefined at Object.writeFileSync.

The error tells you what types of values are acceptable. Provide one of those. A string would be simplest.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda