In order to run a local version of the v5 server (or most of our nodejs server repositories) it is necessary to set up a few things. You will need:
- The server code
- NodeJS
- NPM
- Redis-Server
The server code can be found on beanstalk, check it out with your preferred git client. The environment installation is different depending on your environment.
Installing on Mac
The easiest way to install everything you need is to use Homebrew, so go ahead and install that with the one line command from their website. These next commands will install NodeJS, npm, Redis, and Postgres.
brew update
brew install node
brew install redis
brew install postgres
Navigate to the directory you checked out the server code at and run npm install. It will install all the dependencies the project needs. You will need a local Redis server running before you run the server.
Installing on Windows
Installing on Windows can be tricky because there is varying support for server modules that are mainly for Linux. The best way I’ve found is to install the Windows Linux Subsystem for Windows 10 (https://msdn.microsoft.com/en-us/commandline/wsl/install_guide?f=255&MSPPError=-2147217396). This gives you an Ubuntu installation and the Bash terminal.
First is to update and get all the packages you need from apt-get.
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
If you now try to do an npm install in the v5 server directory you’ll get an error when it tries to install libpq. This is currently a quirk of the WSL and might be fixed later. For now you need to install the -dev version of the PostgresQL package.
sudo apt-get install libpq-dev
You might be required to make a symbolic link from node to nodejs. This is because newer versions of NodeJS have their executable named nodejs and previous versions were just node.
sudo ln -s /usr/bin/nodejs /usr/bin/node
Now you can successfully install project dependencies with npm:
npm install
Before running the server, you’ll need to install and run a local Redis server. The server cannot be started with just the redis-server command or it cannot be reachable for some reason (another quirk of the WSL environment).
sudo apt-get install redis-server
sudo service redis-server start # Starts the redis server as a service
Updating NodeJS and NPM to a specific version
As of this writing, the team is using NodeJS v8.1.2 and npm v5.4.2.
You can switch your node version easily by using the npm package called “n”. Install the package globally and update the versions of NodeJS and npm with these commands:
sudo npm install -g n
sudo n 8.1.2
sudp npm install -g npm@5.4.2
Note, the version of npm is not as important as the version of NodeJS as long as it works.
Running the Node Server
Typically, the server projects need to be run with an environment, typically specified as the NODE_ENV environment variable.
NODE_ENV=development node server