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

141
Vistas
Update JSON with express

I would like to send json updated on post response with express. Currently on my response the json is send but without to be updated.

Below function to edit json:

function editJSON(fr,en,es){
    var obj = {
        list_words: []
    }
    fs.readFile('./assets/words.json', 'utf-8', (err, jsonString) =>{
        if(err){
            console.log(err)
        }else {
            try{
                obj  = JSON.parse(jsonString)
                obj.list_words.push({fr: fr, en: en, es: es})
                json = JSON.stringify(obj)
                fs.writeFile('./assets/words.json',JSON.stringify(null, 2),function (err){
                    console.log("test")
                    if (err) throw err;
                    console.log('complete');
                })
            } catch (err){
                console.log(" Error parsing JSON", err)
            }

        }
    })
}

and post request

const words = require('./assets/words.json')
app.post(
    '/addwords',
    (req,res)=>{
        const errors = validationResult(req);
        console.log(req.body)
        const fr = req.body.fr
        const en = req.body.en
        const es = req.body.es
        editJSON(fr,en,es)
        console.log(words)
        res.json(words) // old JSON is send
})

about 4 years ago · Juan Pablo Isaza
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