Created
October 9, 2015 20:38
-
-
Save paulodiovani/4d12a1e5d640e4aa4f7a to your computer and use it in GitHub Desktop.
Write request headers and data to stdout
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
| 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