How to send a custom http status message in node / express?
express, node.js
Solution
You can check this `res.send(400, 'Current password does not match')` Look express 3.x docs for details
UPDATE for Expressjs 4.x
Use this way (look express 4.x docs):
res.status(400).send('Current password does not match');
// or
res.status(400);
res.send('Current password does not match');
Problem
My node.js app is modeled like the express/examples/mvc app. In a controller action I want to spit out a HTTP 400 status with a custom http message. By default the http status message is "Bad Request": ``` HTTP/1.1 400 Bad Request ``` But I want to send ``` HTTP/1.1 400 Current password does not match ``` I tried various ways but none of them set the http status message to my custom message. My current solution controller function looks like that: ``` exports.check = function( req, res) { if( req.param( 'val')!=='testme') { res.writeHead( 400, 'Current password does not match', {'content-type' : 'text/plain'}); res.end( 'Current value does not match'); return; } // ... } ``` Everything works fine but ... it seems not the the right way to do it. Is there any better way to set the http status message using express ?