Skip to content

Part 1. Initialize & Run the Server

Rachel edited this page Sep 20, 2017 · 5 revisions

Step 1: Set environmental variables

Before we actually start running the NodeJS server (aka the hub), we need to set two important parameters:

1: IS_HUB_PORT: The default port that the server uses is 80 - the most common port of them all. IP addresses specify machine; ports specify specific services on that machine. That being said, port 80 is already being used by the Pi. In fact, the first 1000 ports are already being used by the Pi. So we need to set this to something above 1000, like, say, 8080.

Note: If you start the server using super user privileges (sudo), then you can run on port 80

To set the port to something different, we can create an “environmental variable”, or a variable that is accessible by the entire system (depending on where you put it):

$ export IS_HUB_PORT=8080

2: IS_API_ACCESS_KEY: This is how the hub knows which Initial State account to send the data it receives to.

We’re going to create another environmental variable with our access key. Run this command, replacing “Your_Access_Key” with the access key from your Initial State account (available under "Manage my account"):

$ export IS_API_ACCESS_KEY=“Your_Access_Key”

Note: This way of exporting environmental variables is temporary - they will disappear after powering down or rebooting the Pi. To export them permanently, run: echo "export IS_HUB_PORT=8080" >> ~/.bashrc and echo "export IS_API_ACCESS_KEY="access_key"" >> ~/.bashrc

Step 2. Start the hub

To actually start running the hub, make sure that you are in the node-hub directory:

$ cd node-hub

Run this command (if you want it to run in the background, place & at the end):

$ npm start

When you see "Node-hub serving on Port 8080" (or whatever port you set it to), your hub is up and running!

Now to actually send data to it...

<< Part 1: Initial State - Part 2: Using the Hub >>

Note: I tried everything to make the server restart on reboot - crontab, bash, forever, pm2 - but to no avail. Just know that if your Pi gets turned off, you'll need to restart the server.