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

162
Vistas
How i Can Update my Json data in Express.js

I need help:

I saved my Discord bot ping in a JSON file and I want to show the ping from the JSON file in my web server using HTML. I am using Express.js.

This here is a picture of the data but it's not getting updated when it changes in the JSON file.

enter image description here

This in my express project:

app.get('/', function(req, res){
    const pingsBots = require('./Database/BotPing.json')

    const pingofbot = pingsBots.thepingofbot.botping

    let file = fs.readFileSync(path.join(__dirname, './html/', 'main.html'), { encoding: 'utf-8' })
    file = file.replace("$$theping$$", pingofbot)

    
    res.sendFile(path.join(__dirname, './html/', 'main.html'))
    res.send(file)
    
})

And this in ready method in my bot:

setInterval(function(){
        let Pusher = JSON.parse(fs.readFileSync('./Database/BotsPing.json', 'utf8'));
        Pusher["thepingofbot"] = {
            botping: `${client.ws.ping}`
        }
        async function SavePingData(path, JSONdata){
            fs.writeFileSync(path, JSON.stringify(JSONdata, null, 2))
        }
        SavePingData('./Database/BotsPing.json', Pusher)
    }, 1000)

B.t.w.: Express project not with the bot project.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

app.get('/', function(req, res){
    const pingsBots = require('./Database/BotPing.json')
    const pingofbot = pingsBots.thepingofbot.botping
    let file = fs.readFileSync(path.join(__dirname, './html/', 'main.html'), { encoding: 'utf-8' })
    file = file.replace("$$theping$$", pingofbot) 
    res.sendFile(path.join(__dirname, './html/', 'main.html'))
})
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