Node.js hosting on OpsCaptain

OpsCaptain Node.js hosting platform allows you to run and scale Node.js apps in the cloud of your choice without the pain of managing deployments, builds, proxies and configuring databases. You can do all of this with a simple point and click interface and the CLI.


Install the opscaptain-cli on your local machine and also log in. If you haven't, run the below commands from your terminal to install it and login:

npm install -g opscaptain-cli opscaptain login -em -pw ******

You must have already added the server that will be used to host your Node.js app. To add a server to your OpsCaptain account, follow this guide here.

If you do not have a server yet, you can purchase a server or use the free tier or credit from one of the following clouds: AWS EC2, Microsoft Azure, Vultr, DigitalOcean and Google

Step 1. Create your Node.js app

From the dashboard: Log into the dashboard and create a new app using this link. Once the app is created, you can then proceed to deploy your code to it.

Step 1. Ensure your Node.js app is ready to run in production

The runtime exports a variable with name PORT. You must listen for incomming connections using this variable instead of hardcoding any random port in your code which will only work in your local environment but not anywhere else.

Check out the below examples and how to properly configure the listen port for your Node.js app

var express = require('express'); var app = express(); // Use process.env.PORT instead of hard coded ports app.listen(process.env.PORT);

Step 3. Create the ocmanifest.json file and set environment variables.

Create a file in the folder that contains your project. Name this file ocmanifest.json. Enter any environment variables you may want to set and also the name of your app. In our case the name of our app is [helloworld]. We do not have any environment variables so we will not set any.

{ name: "helloworld", env: {} }

Step 4. Run opscaptain deploy to launch your app

CD into the project directory. Once there, run the below command to deploy

opscaptain deploy