How to deploy and manage Node.js apps with Nesabox
Tags: node, devops, javascript, nesabox
Published: 2019-09-27 20:20:49

---
title: How to deploy and manage Node.js apps with Nesabox
published: true
canonical_url: https://katifrantz.com/how-to-deploy-and-manage-node-js-apps-with-nesabox/
description: Managing and deploying Node.js applications in production can be made super easy with Nesabox. Here's how.
tags: nodejs,devops,javascript,nesabox
---


This is a step by step guide for deploying and managing a Node.js application using Nesabox. As a sample project, we'll be deploying a [strapi application](https://github.com/bahdcoder/strapi-nesabox-demo) but this tutorial would work for any Node.js framework or project.

##### Requirements
- A free [Nesabox account](https://nesabox.com)

##### Creating a virtual private server

The first thing we need is a VPS to host our application. You can obtain one of almost any size from server providers such as [Digital Ocean](https://digitalocean.com), [Vultr](https://vultr.com), [Linode](https://linode.com) and [AWS](https://aws.amazon.com). Nesabox connects your account with these providers to make it easy to provision a server. You can also obtain a VPS from any provider of your choice running Ubuntu 18.04 and connect it to your Nesabox account. 

In this example, we'll use Digital Ocean, but any provider would work just fine. Visit your [account settings page](https://app.nesabox.com/account/applications) to connect your provider by adding an API token obtained from Digital Ocean (Or your chosen provider).  

Once done, [visit your dashboard](https://app.nesabox.com) to provision a server.

![Provision server form](https://res.cloudinary.com/bahdcoder/image/upload/v1569549685/Screenshot_2019-09-27_at_03.00.16_or5mg2.png)

Be sure to select the databases you'll need on this server. In this case, I selected all databases supported by [Strapi](https://strapi.io).

The provisioning takes abut 10 minutes. During this time, Nesabox installs all necessary packages, databases, and configures the server for production.

##### Creating a database

Once your server is ready, click to manage it. You should see the `Mongodb` tab. You can manage your Mongodb installation here by adding new databases and users.

![Mongodb management tab](https://res.cloudinary.com/bahdcoder/image/upload/v1569551552/Screenshot_2019-09-27_at_03.32.18_qgfyfm.png)

Add a new database. We'll connect our application to this database.

![Mongodb management tab](https://res.cloudinary.com/bahdcoder/image/upload/v1569551779/Screenshot_2019-09-27_at_03.35.51_nsydev.png)

We need to add a new database user to this database to access it. Click on the `people` icon to manage database users.

Add a database user with password.

![Add a database user](https://res.cloudinary.com/bahdcoder/image/upload/v1569552427/Screenshot_2019-09-27_at_03.37.13_dan2h3.png)

##### Creating a site

Visit the `Sites` tab and add a new site. The name of the site should match the domain of your site. 

![Add a site](https://res.cloudinary.com/bahdcoder/image/upload/v1569552596/Screenshot_2019-09-27_at_03.49.40_cgydtt.png)


##### Connecting site to Github repository.

Click to manage the newly created site. To connect the site to Github, you need to connect your account to Github from your [account applications page](https://app.nesabox.com/account/applications). Once connected, provide the repository and branch for the application. In this case, [bahdcoder/strapi-nesabox-demo](https://github.com/bahdcoder/strapi-nesabox-demo).


![Add repository](https://res.cloudinary.com/bahdcoder/image/upload/v1569594666/Screenshot_2019-09-27_at_15.30.31_xq5io0.png)

This process would take only a few seconds to clone and install your project repository. 

##### Configuring PM2

PM2 is an advanced production ready process manager for Node.js applications. Nesabox creates an `ecosystem.config.js` file specific to your application on the server.
On the Site `Settings` tab, you can update this file to add execution commands, node versions, environment variables, log files and any other configurations supported by PM2.

On the `Settings` tab, when you click the `Edit PM2 Ecosystem file`, the `ecosystem.config.js` file for this site is fetched securely over `SSH` and placed in an editor for you to edit.

![PM2 Ecosystem configuration file](https://res.cloudinary.com/bahdcoder/image/upload/v1569595972/Screenshot_2019-09-27_at_15.52.30_ob43kd.png)

The first important configurations are the `script:npm` and `args:start`. This instructs PM2 to run the `npm start` command when starting or restarting the application in production.

Next, we have the `interpreter` configuration which is a path to the specific node version this app will run on. By default, it's the latest stable version.

We can also configure all environment variables for our project in the `env` object. The `PORT` environment variable is automatically generated by Nesabox. If you need to change this, then you also have to make sure the Nginx configuration proxies to your new port too.

For this application, all the environment variables really needed are database configurations. The `DATABASE_NAME`, `DATABASE_USERNAME` and `DATABASE_PASSWORD` all match the MongoDB credentials we created earlier.

##### Setting up deploy script

The `Deploy Script` is the script Nesabox runs on your server on every deployment. By default, it pulls the latest changes from the deployment branch, installs `npm` dependencies and restarts the application with `PM2`. 

For this application, we'll need to build the application before starting it. We'll modify it as follows:

![Deploy Script](https://res.cloudinary.com/bahdcoder/image/upload/v1569599312/Screenshot_2019-09-27_at_16.48.12_p1z1lv.png)

It simply runs the `npm run build` command before starting with PM2.

##### Deploy your application

To deploy, click deploy 🚀 ! You can monitor the deployment in real time too.

To view your application, be sure to point your site domain to your server. 

🎉🎉🎉
![Deployed Site](https://res.cloudinary.com/bahdcoder/image/upload/v1569600021/Screenshot_2019-09-27_at_17.00.02_nn6ca7.png)


##### BONUS - Secure your site with Let's Encrypt

On the `SSL` tab, with one click, you can secure your site with a Let's Encrypt SSL certificate.

🎉🎉🎉
![Secured site](https://res.cloudinary.com/bahdcoder/image/upload/v1569600299/Screenshot_2019-09-27_at_17.04.45_dm3sue.png)

##### Conclusion

Nesabox makes deployments and application management really easy. This article is just the tip of the iceberg. Please reach out with questions if you have any. Thank you for reading this far!