Here is the tutorial for deploying your Node.JS API to your server.
Fast forward version
– copy files to web server
– adjust db credentials if needed
– `sudo npm install`
– `node app.js`
Once you generate an API file, follow these steps to be up and running.
– Copy Files to Your Web Server
– UnZip / UnTar Files
– Install Node Dependencies
– (optional) Update Database Credentials
– (Advanced) Generate Upstart Script
Let’s look at each step closely.
##Copy Files to Your Webserver
You can use scp, FileZilla or your transfer method of choice. Our NodeJS package have it’s own web server so you can copy it anywhere you want.
##UnZip / UnTar Files
`tar -zxvf yourfile.tar.gz`
##Install Node Dependencies
We assume you have npm already installed in your system. Simply run
`sudo npm install` to make sure all dependencies are installed.
##(Optional) Update Database Credentials
We are big on data privacy, so if you opted to upload your schema, you need to go inside `/databases/` and update your credentials
Simply type `node app.js` to run your code and connect to your API.
##(Advanced) Generate Upstart Script
There are many ways to make sure that your node instance(s) are up and running. Some developers fancy forever library. We love to generate upstart scripts.
(Don’t forget to replace [yourapi] part.
`sudo vim /etc/init/[yourapi].conf`
and type in following script
start on started mountall
stop on shutdown
respawn limit 99 5
exec nodejs [YOUR API PATH]/app.js >> /var/log/[yourapi]-node.log 2>&1
This way you can simply do `[yourapi] start` and `[yourapi] stop` to control your api. On plus side, it’ll automatically start each time your system reboots.