Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

319
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda