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

215
Views
TypeError [ERR_INVALID_ARG_TYPE] WHY IS THIS HAPPENING

I don't know what I'm doing wrong. I've done everything 'perfect' from my knowledge.

The error is happening at writeParams. Why is this happening?

Code

const fs = require('fs');
const path = require('path');
const paramsPath = path.join(__dirname, 'params.json')

function writeParams(data) {
    console.log("Writing params.json file. . .", data);
    return fs.writeFileSync(paramsPath, JSON.stringify(data))
}

function readParams() {
    console.log("Reading 'params.json' file. . .");
    const data = fs.readFileSync(paramsPath);
    return JSON.parse(data.toString());
}

Error

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 (node:fs:2146:5) at writeParams (E:\TB\JS\index.js:8:15) at Timeout.main [as _onTimeout] (E:\TB\JS\index.js:85:9) at processTicksAndRejections (node:internal/process/task_queues:96:5)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I recreated your error. Your code is completely valid and works as long as you pass writeParams a valid Javascript object. The only way your error could occur would be if you forgot to give writeParams some data.

Mistakes like this happen often and can be extremely frustrating. If you are getting too frustrated at a program, your ability to fix the problem can be hindered. I'd recommend doing some other tasks (taking a walk, doing the mountain of dishes in your sink, etc.) and coming back to programming next time an error like this occurs.

Heres my test code:

const fs = require('fs');
const path = require('path');
const paramsPath = path.join(__dirname, 'params.json')

function writeParams(data) {
    console.log("Writing params.json file. . .", data);
    return fs.writeFileSync(paramsPath, JSON.stringify(data))
}

function readParams() {
    console.log("Reading 'params.json' file. . .");
    const data = fs.readFileSync(paramsPath);
    return JSON.parse(data.toString());
}

writeParams({foo: "bar"})
console.dir(readParams())
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!