How I Found A Job With Node + Angular, Part 6: Going Production

The previous post in this series was almost a year and a half ago. A lot has happened in this time. The tension took some 2 months to resolve, and the new job that I got demanded some attention. I know I promised to enhance the mapping functionality and show some filtering tricks, but I decided to write this post about deploying the app to a production server, and share my findings with you.

For the production server, I choose to go with DigitalOcean. You can read here about some of the reasons behind this decision. To get started, you should create you’re account with DigitalOcean, and when you are ready to start your droplet, you are presented with a lot of pre-built stacks to choose from:

digital-ocean-stacksI choose the node stack and the weakest server possible (5$/month). With a sign in coupon of 10$ you get 2 months of server usage for free.

digital-ocean-node-stackOnce you droplet is created, open ssh connection with it (there is a lot of help document describing how to use the DigitalOcean droplets. You credentials should arrive by mail after the droplet is created). Check that node is running by: node -v

root@ubuntu-512mb-nyc3-01:~# node -v
v4.2.3

Great! Node is running. Let’s install the Couch DB. Follow the instructions here. If everything is ok, you should see this:

root@ubuntu-512mb-nyc3-01:~# curl localhost:5984
{
   "couchdb":"Welcome",
   "uuid":"a260bce11435fb728d7e7c31f1e0a340",
   "version":"1.6.1",
   "vendor":{
      "name":"Ubuntu",
      "version":"14.04"
   }
}

Follow the additional steps to install Futon. If you followed the instructions carefully, you should see the futon control panel in your browser (after you created the tunnel by:

ssh -L5984:127.0.0.1:5984 user@your_server_ip

Like this:
digital-ocean-futonThe next step will be to upload all your application files from your development machine to this newly created server. Once uploaded, let’s try to run the app (don’t forget to install all the required dependencies with npm and bower – see the previous post, and remember to run node server.js on the server), and point the browser to our server ip:

digital-first-runHmmm. It seems that there is no data. Why? Because we didn’t create the table and imported the data into it yet…

If we run the data importer node app (remember the job-importer.js we discussed in the previous posts?), we encounter the first production world issue. the database and all it’s documents are not created. debugging the js script with the help of some curl commands reveal that couch is unhappy:

{"error":"unauthorized","reason":"You are not a server admin."}

And this is because one of the steps in the couch db installation was to create an admin user. To resolve this problem, the creation urls should be corrected:

instead of: var nano = require('nano')('http://localhost:5984');
we should use: var nano = require('nano')('http://admin_user_name:admin_password@localhost:5984');

Now the importer should run smoothly, and we get the map shown at the end of part 5 (How I Found A Job With Node + Angular, Part 5: Mind The Map)

In the next post we’ll see some NoSQL magic and Couch tricks for data lookup without views.

How I Found A Job With Node + Angular tutorial series:

Part 1: Let’s Do Some Node
Part 2: Let’s Level Some Jobs
Part 3: The Angular Angle
Part 4: Strap The Boot
Part 5: Mind The Map
Part 6: Going Production

Leave a Reply

Your email address will not be published. Required fields are marked *