Skip to content

Instantly share code, notes, and snippets.

@lancefisher
Created January 2, 2012 06:49
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 lancefisher/1549634 to your computer and use it in GitHub Desktop.
Save lancefisher/1549634 to your computer and use it in GitHub Desktop.
Node.js Code for Twilio Rube Goldberg Contest
var http = require('http');
var qs = require('querystring');
http.createServer(function (req, res) {
if (req.method === 'POST') {
var body = '';
req.on('data', function(data) {
body += data;
});
req.on('end', function() {
var post = qs.parse(body);
console.log('POST params:')
console.log(post);
//set the nixie tubes by sending a request to the netduino
var options = {
host: 'XXX.XXX.XXXX.XXX', //IP Address to my cable modem
port: 8888,
path: '/numbers/' + post.Body,
};
console.log('sending GET to netduino');
console.log(options);
http.get(options, function(netduinoRes) {
console.log('response from netduino: ' + netduinoRes.statusCode);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Happy New Year! We set the nixie tubes!')
res.end();
});
});
return;
}
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('{ "ok": true }')
res.end();
return;
}).listen(8080);
console.log('server started on port 8080');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment