Created
May 21, 2015 02:57
-
-
Save ericdcobb/143ba181315a43e2a389 to your computer and use it in GitHub Desktop.
simple node webserver that just prints all posted requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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