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

199
Views
Returning updated config.json file (MERN app)

I am using node file system module for the first time to store a config.json file that could be edited from front-end. I am able to read create config.json file and read the file separately.

However, I want to update the file and return the saved file in the same request. How do I do the same efficiently

//To Set config file & return data
router.post('/write-config', adminAuth, (req, res) => {
   console.log(`admin wants to update config`) ;

   const {config} = req.body ;

   try {
       fs.writeFile(__dirname+'/data/config.json', JSON.stringify(config), (err) => {
         if (err) throw err ;
         console.log('Configuration saved successfully.') ;
       });
       //res.json("ok") ;
       /* return the data from file which we just saved */ 
   }
   catch(err) {
       console.log(err.message) ;
       res.status(400).json(err.message) ;
   }
}) ;
about 4 years ago · Juan Pablo Isaza
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!