Saturday 29 December 2018

Changing index.html content through server response.

That should be fairly easy, but I couldn't figure it out. I have an index.html, a client.js file and a server.js file.

App

Hello Message

client.js is for making requests to server.jsdocument.querySelector('.button').addEventListener('click', function(e) { fetch('/fetchAll', {method: 'POST'}) }); In server.js I listen to these requests and run certain functions// serve the homepage app.get('/', (req, res) => { res.sendFile(__dirname + '/index.html') }) app.post('/fetchAll', (req, res) => { browserWindow() }) Let's say helloFunc() sets a variable; const helloMessage = "Hello there"I want to be able to change the content of the index.html in accordance with helloMessage variable.How can I do that?Also, sometimes helloFunc() might be async. In this case how can I listen to it's completion to send a data to html page?

Submitted December 29, 2018 at 07:00AM by eligloys

No comments:

Post a Comment