Skip to content

Instantly share code, notes, and snippets.

@jdpaton
Created May 22, 2013 06:56
Show Gist options
  • Save jdpaton/5625726 to your computer and use it in GitHub Desktop.
Save jdpaton/5625726 to your computer and use it in GitHub Desktop.
Simply return any custom HTTP code by supplying the url param ?code=302
var url = require('url');
var http = require('http');
var querystring = require('querystring');
// Example usage: curl -I http://localhost:1337/?code=500
http.createServer(function (req, res) {
var purl = url.parse(req.url).query;
var qs = querystring.parse(purl);
var status_code = qs.code || 200;
res.writeHead(status_code, {'Content-Type': 'text/plain'});
res.end('Hello Status code: ' + status_code + '\n');
}).listen(process.env.PORT || 1337);
console.log('Server running at http://127.0.0.1:1337/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment