Skip to content

Instantly share code, notes, and snippets.

@paulodiovani
Created October 9, 2015 20:38
Show Gist options
  • Select an option

  • Save paulodiovani/4d12a1e5d640e4aa4f7a to your computer and use it in GitHub Desktop.

Select an option

Save paulodiovani/4d12a1e5d640e4aa4f7a to your computer and use it in GitHub Desktop.
Write request headers and data to stdout
http = require('http')
###
Usage:
coffee index.coffee 3000
###
server = http.createServer (req, res) ->
console.log "\n\nHEADERS:\n", req.headers
req.on 'data', (data) ->
try
json = JSON.parse data.toString()
body = JSON.stringify json, null, 2
catch
body = data.toString()
console.log "\nDATA:\n", body
res.writeHead 500, 'Content-Type': 'text/plain'
res.end('nothing to show')
server.listen process.argv[2] || 3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment