Advertisement
Guest User

index.js

a guest
Dec 15th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var app = require('express')();
  2. var http = require('http').Server(app);
  3. var io = require('socket.io')(http);
  4. var request = require('request');
  5. app.get('/', function(req, res){
  6.   res.sendFile(__dirname + '/index.html');
  7. });
  8. io.on('connection', function(socket){
  9.   console.log("connected");
  10.   });
  11. io.on('color cycle', function(){
  12.   console.log("Button Pressed");
  13.   request({
  14.         url: "xxxxxxxxxx",
  15.         method: "POST",
  16.         json: {"value": "1"},
  17.         headers: {
  18.           "Content-type": "application/json",
  19.           "X-AIO-KEY": "xxxxxxxxxxx"
  20.         },
  21.     }, function (err, resp, body) {
  22.       if ( !err && body) {
  23.           console.log("Body: "+body);
  24.       } else if (err) {
  25.           console.log("Error: "+err);
  26.       }
  27.       console.log("Response: "+resp);
  28.   })
  29. })
  30. http.listen(8080, function(){
  31.   console.log('listening on *:8080');
  32. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement