Skip to content

Instantly share code, notes, and snippets.

@D-32
Last active November 6, 2015 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save D-32/cfd277b010b3c5361420 to your computer and use it in GitHub Desktop.
Save D-32/cfd277b010b3c5361420 to your computer and use it in GitHub Desktop.
Simple node server to debug stuff
http = require('http');
fs = require('fs');
url = require('url');
server = http.createServer( function(req, res) {
console.log(req.url)
if (req.method == 'POST') {
var body = '';
req.on('data', function (data) {
body += data;
});
req.on('end', function () {
console.log("POST: " + unescape(body));
});
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello POST!');
} else {
var url_parts = url.parse(req.url, true);
var query = url_parts.query;
console.log("GET: " + JSON.stringify(query));
res.writeHead(200, {'Content-Type': 'text/html'});
res.end("Hello GET!");
}
console.log("-------");
});
server.listen(8000);
console.log("Server running at http://127.0.0.1:8000/");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment