Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

321
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!