Skip to content

Instantly share code, notes, and snippets.

@akuhn
Created August 19, 2013 20:24
Show Gist options
  • Save akuhn/6273651 to your computer and use it in GitHub Desktop.
Save akuhn/6273651 to your computer and use it in GitHub Desktop.
var http = require('http');
var shared = {count: 0}
var server = http.createServer(function (req, res) {
console.log([req.method,req.url])
res.writeHead(200, {'Content-Type': 'text/plain'})
res.write('You called me ' + (shared.count += 1) + ' times!\n')
res.write('You are looking at ' + req.url + '\n')
res.end()
})
server.listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
// node server.js
// curl -X GET http://127.0.0.1:1337
// curl -X POST http://127.0.0.1:1337 -d '{"text":"Hello worlds!"}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment