Maher Mahouachi Maher Mahouachi - 6 days ago 9
JSON Question

Send JSON data from express to html NodeJS

Hello all i'm new with node so here my use case i want to post data to my express app and show it on a html page is that possible with nodeJs ?

Here my code

app.post('/', function(req, res){
res.sendFile(__dirname + '/views/index.html', {data: req.body});
})

Answer

There are many tutorials showing how to do that. I would recommend first you understand how HTTP protocol works (The message structure : https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html). Then go dive into node and exchange data through requests and responses. I'd recommend body-parser to arrange the data format between the two sides. Also read the express documentation. Hope it helps.