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

153
Views
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 answers
Answer question

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 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!