Skip to content

Instantly share code, notes, and snippets.

@Mumakil
Last active August 29, 2015 14:24
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 Mumakil/4117cbbd8bf415c9a6bd to your computer and use it in GitHub Desktop.
Save Mumakil/4117cbbd8bf415c9a6bd to your computer and use it in GitHub Desktop.
Echo server
node_modules/

Echo server

This is a simple node app that you can use to print out any incoming web requests. Just run

npm install
PORT=8080 npm run server

and then you can send any requests with any path to localhost:8080.

express = require 'express'
bodyParser = require 'body-parser'
http = require 'http'
port = process.env.PORT || 8000
app = express()
app.use bodyParser.json()
app.use bodyParser.urlencoded(extended: true)
app.all '*', (req, res) ->
console.log "Request", req.path
console.log req.body
res.status(204).send('')
server = http.createServer(app)
server.listen(port)
console.log "Started echo server on port #{port}"
console.log "Send any requests to any path under http://localhost:#{port}/ and I'll echo the body."
{
"name": "echo_server",
"version": "1.0.0",
"description": "Captures webrequests and prints out the body.",
"main": "app.coffee",
"dependencies": {
"body-parser": "^1.13.2",
"coffee-script": "^1.9.3",
"express": "^4.13.1",
"qs": "^4.0.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"server": "coffee echo_server.coffee"
},
"repository": {
"type": "git",
"url": "git@gist.github.com:/4117cbbd8bf415c9a6bd.git"
},
"author": "Otto Vehviläinen <vehvis@flowdock.com>",
"license": "ISC"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment