send Index.html file with JSON data back to user when loading the page?

  express, javascript, node.js

I am working on this single page app where I send the App.html file to use after login and then I want to fill that file with the data from the database.
I cannot find a way to simply do 2 get requests at the same time since one is for the file the other is for the data.
any work arounds ? as I have been reading you cannot send 2 requests for the same URL.
and since serving the file is eliminating my response window how can I implement this then?.
I want to stay on the same page so different rout will not work because it’s going to redirect me somewhere else and I will lose my access to the App.html that is in the browser.
I also read that there is an option parameter in send file but it hasn’t been working for me.

// Express Code

//Controler File 
exports.getApp =  async(req, res, next) => {
    //app
    res.sendFile(await path.join(__dirname, '../', 'views', 'App.html'))
}

exports.getData =  async (req, res, next) => {
    //data
    const getData = await DB.find()
    res.json(getData)
}




// Routes File 
app.route('/app')
    .get(toAppControler.getApp)
    .get(toAppControler.getData)

Source: Ask Javascript Questions

LEAVE A COMMENT