Skip to content

Instantly share code, notes, and snippets.

@ericdcobb
Created May 21, 2015 02:57
Show Gist options
  • Save ericdcobb/143ba181315a43e2a389 to your computer and use it in GitHub Desktop.
Save ericdcobb/143ba181315a43e2a389 to your computer and use it in GitHub Desktop.
simple node webserver that just prints all posted requests
{
"name": "basic-node-server",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.12.4",
"express": "^4.12.4"
}
}
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var jsonParser = bodyParser.json();
// respond with "hello world" when a GET request is made to the homepage
app.post('/*', jsonParser, function(req, res) {
console.log('Path: '+req.url);
console.log('Body: ' + JSON.stringify(req.body));
console.log('\n');
res.send('Hello World!');
});
var server = app.listen(1337, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment