How do I deploy a Harp app on DigitalOcean

August 9, 2014 2k views

I created a website with Harp.js (harpjs.com), but I have no clue how to deploy it on my DigitalOcean server. Can someone please help?

3 Answers

See How To Use PM2 to Setup a Node.js Production Environment On An Ubuntu VPS. You can use the user you created while following Initial Server Setup with Ubuntu 14.04 as the "safeuser".

by Jim Cassidy
Use these instructions to setup an Ubuntu server to run Node.js applications, including apps based on Express, Geddy, or Sails. This will help you avoid some security mistakes and will provide some surprising benefits.

host it with pm2, here is what I do with vagrant. structure like
/var/www/hp.com/package.json
/var/www/hp.com/node_modules
/var/www/hp.com/hpserver.js # the server, which will be hold by pm2
/var/www/hp.com/html # site content, so here are the harp-content like html/harp.json , html/public/articles , html/public/index.jade

  1. node -v
    I use nvm to install node, which you can use some alternative way. The point is node version.

    curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
    nvm install 4.4.3 ( dont run nvm install stable because it will install v6.0.0 which is not robust yet )
    nvm alias default 4.4.3
    nvm use default

  2. Nginx

    sudo touch /etc/nginx/sites-available/hp.com
    sudo nano /etc/nginx/sites-available/hp.com

    server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    server_name localhost;
    #server_name lorem.com www.lorem.com; # the domain
    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass         http://127.0.0.1:9000;
    }
    }
    

    ref Ghost (a node blogging app) Nginx setting
    https://www.digitalocean.com/community/tutorials/how-to-host-ghost-with-nginx-on-digitalocean

  3. site content

    sudo mkdir -p /var/www/hp.com/html
    sudo chown -R $USER:$USER /var/www/hp.com/html
    sudo chmod -R 755 /var/www
    npm install -g harp ( will install 0.20.3 and it is ok for harp cmd , but not for the server )
    harp init /var/www/hp.com/html --boilerplate kennethormandy/hb-remedy
    site content in /var/www/hp.com/html/public with /var/www/hp.com/html/harp.json (site info)

  4. /var/www/hp.com/hpserver.js

    cd /var/www/hp.com
    touch package.json
    echo "{}" >> package.json
    npm install harp@0.19.0 --save
    echo "require('harp').server(__dirname+'/html', { port: process.env.PORT || 9000 })" >> /var/www/hp.com/hpserver.js

    Test-to-run: node /var/www/hp.com/hpserver.js and should have no error. If you don't specify harp@0.19.0 then there might be errors ( like asking to do npm rebuild node-sass or the libsass binding was not found ) in harp@0.20.3 (the latest version which would do default install)
    ref
    http://harpjs.com/docs/deployment/azure

  5. pm2

    npm install -g pm2
    pm2 startup ubuntu # then do as prompt cmd

    then restart vps

    pm2 start /var/www/hp.com/hpserver.js
    pm2 dump && pm2 kill && pm2 resurrect
    Now as the vps starts, pm2 will trigger hpserver.js and serving every changes to /var/www/hp.com/html.
    For back up, just save the whold hp.com dir ( hpserver.js + package.json + node_modules dir + html dir )

by Alex LaFroscia
This is our tutorial on hosting Ghost with Nginx on DigitalOcean.
Have another answer? Share your knowledge.