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

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

0

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

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