Skip to content

Instantly share code, notes, and snippets.

@mohitathwani
Last active August 29, 2015 13:57
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 mohitathwani/9829480 to your computer and use it in GitHub Desktop.
Save mohitathwani/9829480 to your computer and use it in GitHub Desktop.
Sample code for the IoT Blog post
//We first load the express framework and make it available for our script
var express = require('express');
//Here we initialize the express framework
var app = express();
//We are going to GET the pin number and the state to set the pin to from the URL from the browser
//For example http://yourdomain.com/25/1 -----> This turns the state of pin number 25 to HIGH
//Similarly: http://yourdomain.com/25/0 -----> This turns the state of pin number 25 to LOW
//NOTE: We can also send a json packet to the server as part of this request, but we won't cover that for now !
app.get('/:pin/:state', function(req, res) {
res.send({pin:req.params.pin, state: req.params.state});
});
//We start the server on port number 3000 and allow it work on all domains.
app.listen(4000, '0.0.0.0');
console.log('Listening on port 4000...');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment