Created
April 29, 2014 00:43
-
-
Save flitbit/11388074 to your computer and use it in GitHub Desktop.
Dead-simple Echo Webserver - expects, returns JSON
This file contains 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'), | |
bodyParser = require('body-parser'), | |
util = require('util') | |
; | |
var app = express(); | |
app.use(bodyParser()); | |
app.get('/', function(req, res){ | |
res.send('You probably want to perform an HTTP POST'); | |
}); | |
app.post('/', function(req, res){ | |
util.log("body: "+util.inspect(req.body, false, 99)); | |
res.json(req.body); | |
}); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run this simple server you should have node.js installed.
The easiest way to run it is to put save
app.js
to a file in a clean directory. Open a terminal and change directories to your new clean directory and run these commands:Once you've got those dependencies in place run:
After the server is running you can send it a post using curl, or any other mechanism that can post JSON.
The sole purpose of this simple server was to sanity check my answer to this question on stack-overflow.