How to deploy Node.js app on a VSP/Cloud server directly from GitHub

In this guide:


What you need

  • Basic Node.js knowledge
  • Basic Git knowledge (2 commands - git commit and git push)
  • Account on GitHub or Bitbucket (if you haven’t, it takes just a few minutes)
  • VPS or Cloud server with SSH access, public IP, and Ubuntu 20.04 (you can get free servers on the first 2 months on DigitalOcean)
  • 5-10 minutes of your time

Project on your local machine

If you already have a Node.js project just skip this step. If you haven’t let’s create a simple web server using Polka - https://github.com/lukeed/polka.

  • Install Node.js and NPM on your local machine if you haven’t done it
  • Install Git on your local machine if you haven’t done it
  • Create a new folder (for example, in your home directory)
    mkdir starter
    cd started
    npm init
  • Add Polka to your project
    npm install polka --save
  • Edit your main js file (you specified it in ‘npm init’). In our case, it’s index.js which should have the code below
    const polka = require('polka');
    
    function one(req, res, next) {
      req.hello = 'world';
      next();
    }
    
    function two(req, res, next) {
      req.foo = '...needs better demo 😔';
      next();
    }
    
    polka()
      .use(one, two)
      .get('/users/:id', (req, res) => {
        console.log(`~> Hello, ${req.hello}`);
        res.end(`User: ${req.params.id}`);
      })
      .listen(3000, () => {
        console.log(`> Running on localhost:3000`);
      });

Here we create a Polka webserver and run it on port 3000

  • Run your app
    node index.js
  • Check that the app isn’t crashed. You’ll see in Terminal something like
    > Running on localhost:3000
  • Push this project to GitHub, Bitbucket or GitLab. You can use any git server to deploy projects using Deployed.cc

Connect a VPS/Cloud server

Deployed.cc is a service to deploy web apps on VPS/cloud server directly from git repositories.

To deploy your projects you should connect to at least 1 server:

  • Create a free account on deployed.cc
  • In your account click on “+ Server”
  • Follow instructions and connect your server

It will take around 5 minutes. After that, you can deploy as many projects as you want while your server has free resources.


Create a Deployed project and connect your GitHub repository

Deployed.cc uses Git to manage deployment that’s why you don’t need to learn new commands or configuration files to deploy your projects. You should just connect your remote git repository (private or public; GitHub, Bitbucket, GitLab, or even on your custom Git server).

  • In your account click on “+ Project”
  • Select a server to deploy the project
  • Follow instructions to connect your remote Git repository
  • Click Deploy

That’s it. Wait a few minutes and check that your Node.js is live


(Optional) Create environments and check how ‘Push-to-Deploy works

Before putting your project in production we recommend creating at least 2 environments (production and development) even if you’re a 1-2 person team. Deployed.cc allows to create of an unlimited amount of environments and “map” the git branches. Let me show you a simple example. For example, you have 2 branches - master and dev. You can create environments for these 2 branches and have 2 instances of your project which will be available on different URLs. How it works:

  • Go to your account - deployed.cc/me
  • Select a project you just deployed
  • Click on the environments tab
  • Type in a name for your environment and git branch with the code for that environment
  • Click on Add

When you push some changes to your remote git repository those changes will be deployed automatically. Let’s try it (on your local machine):

  • Go to the root of our project
  • Change text in index.js “…needs better demo 😔” to “…it’s a master branch”
  • Push changes to a remote git repository
  • Check if the URL with the production environment shows this new text

For dev branch:

  • Create a new branch and name it “dev”
  • Change text in index.js “…it’s a master branch” to “…it’s a dev branch”
  • Push changes to the remote git repository
  • Check if the URL with the development environment has “…it’s a dev branch”

What’s next?

I showed the basic features behind Deployed.cc and how it’s easy to deploy projects using our service. Our main idea is to make continuous deployment available for even small teams and solo developers. Follow us on Twitter to get notified about new features, submit your feature request to hey@deployed.cc and focus on the app’s development, not servers.