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

194
Views
Can't write file using FS

So, I have a NodeJS API using express and I want to get data from a HTTP request and store it in a local JSON file. This is the file that contains the function to write the local file:

    const fs = require('fs').promises;
    async function updateData(req,res){
       let { name, phone, email, addres, whatsapp, officeHours} = req.body;
       let configs={
        name:name,
        phone:phone,
        email:email,
        addres:addres,
        whatsapp:whatsapp,
        officeHours: officeHours
      };
       let data = JSON.stringify(configs);
       console.log(data);
       try{
        await fs.writeFile('./configs.json', data);
       }catch(err){
        throw err;
       }
    }
module.exports = {updateData};

And this is the part of the code I use to call the function with the Post route

routes.post('/storedata', storeData.updateData);

When I send the HTTP request, using Insomnia, I don't get any errors and the data is logged in the console, but the file isn't written.

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

0

Try an absolute path like writeFile( __dirname + '/configs.json', data)

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!