I've written the following piece of code in my nodeJS/Expressjs server:
app.post('/settings', function(req, res){ var myData = { a: req.param('a') ,b: req.param('b') ,c: req.param('c') ,d: req.param('d') } var outputFilename = 'config.json'; fs.writeFile(outputFilename, JSON.stringify(myData, null, 4), function(err) { if(err) { console.log(err); } else { console.log("Config file as been overwriten"); } }); });
This allows me to get the submitted form data and write it to a JSON file.
This works perfectly. But the client remains in some kind of posting state and eventually times out. So I need to send some kind of success state or success header back to the client.
How should I do this?
Thank you in advance!
Express Update 2015:
Use this instead:
res.sendStatus(200)
This has been deprecated:
res.send(200)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With