title: How to connect a raspberry pi to a webserver
body: <p>after some coding I got my raspberry pi to work. So I can control an servo with 2 buttons on html open and close. But this is on a local server (raspberrpiIP:3000) and I want to control the raspberry pi on a live website. So everybody in the world should be able to control it. After much research I couldn't find the right answers to connect my raspberry pi with the script to a live website. This is the script for controlling the servo and connecting to the internet.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var http = require('http');
  var express = require('express');
  
  var lockedState = 2200;
  var unlockedState = 500;
  
  var motorPin = 14;
  var buttonPin = 17;
  
  var app = express();
  
  // *** Start code *** //
  
  var locked = true;
  
  //Setup servo
  var Gpio = require(
          motor = new Gpio(motorPin, {mode: Gpio.OUTPUT});
  //setup button
  button = new Gpio(buttonPin, {mode: Gpio.INPUT,
          pullUpDown: Gpio.PUD_DOWN,
          edge: Gpio.EITHER_EDGE
    }),
    servo = new Gpio(motorPin, {mode: Gpio.OUTPUT});
  
  button.on('interrupt', function () {
    motor.servoWrite(lockedState);
   setTimeout(function(){motor.servoWrite(0)}, 2000);
  });
  
  
  
  // ------------------------------------------------------------------------
  // configure Express to serve index.html and any other static pages stored
  // in the home directory
  app.use(express.static(__dirname));
  
  
  //lock rest get call
  app.get('/uit', function (req, res) {
          motor.servoWrite(lockedState);
          locked = true;
          res.send('uit')
          console.log('uit gezet')
          //After 1.5 seconds, the door lock servo turns off to avoid stall current
   setTimeout(function(){motor.servoWrite(0)}, 2000);
   });
  
  //unlock rest get call
  app.get('/aan', function (req, res){
          motor.servoWrite(unlockedState);
          locked = false;
          res.send('aan')
          console.log('aan gezet')
          //After 1.5 seconds, the door lock servo turns off to avoid stall current
          setTimeout(function(){motor.servoWrite(0)}, 2000)
  
  
   });
  // ------------------------------------------------------------------------
  // Start Express App Server
  //
  app.listen(3000);
  console.log('App Server is listening on port 3000');</code></pre>
  </div>
  </div>
  </p>