Skip to content

Instantly share code, notes, and snippets.

@ericychoi
Created November 9, 2016 20:40
Show Gist options
  • Select an option

  • Save ericychoi/a07d3fe8861031b75ed27a348b0a2c3a to your computer and use it in GitHub Desktop.

Select an option

Save ericychoi/a07d3fe8861031b75ed27a348b0a2c3a to your computer and use it in GitHub Desktop.
A simple http sink in node.js
var http = require('http');
var jsonResp = {
"type": "free"
};
var jsonRespPaid = {
"type": "Paid"
}
var port = process.argv[2];
http.createServer(function(request,response){
var body = "";
request.on('data', function(chunk) { body += chunk; });
request.on('end', function() {
console.log('POST: ' + body + "\n");
setTimeout(function() {
response.writeHead(200);
if (request.url.match(/180/)) {
response.write(JSON.stringify(jsonRespPaid))
} else {
response.write(JSON.stringify(jsonResp));
}
response.end();
// process.exit(1);
}, 0)
});
}).listen(port);
console.log("server started at " + port + "\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment