Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send a success status to browser from nodejs/express?

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!

like image 409
jansmolders86 Avatar asked Nov 15 '12 12:11

jansmolders86


1 Answers

Express Update 2015:

Use this instead:

res.sendStatus(200) 

This has been deprecated:

res.send(200)   
like image 82
ac360 Avatar answered Sep 27 '22 20:09

ac360