Skip to main content

Node.js Multi-Process

Deploy multi-process Node.js applications on KloudBean for improved performance and scalability.

Overview

On KloudBean, you get a complete production-ready stack to build and host high-performance Node.js multi-process applications with PM2, with ease and a few simple steps.

You get:

  • Git integration to pull your code on the server
  • SSH access to the server to run commands manually and using ADM tool for quick deployment
  • File Manager access to add, update and manage files with ease
  • PM2 to run multiple processes of your Node.js app

Launching New Node.js Application

note

If you already have a server and want to launch an app on it, go to Applications → Add Application and add a Node.js app on an existing server.

In this example, we will create a brand new server.

In order to launch your first Node.js app on a new server, navigate to the server provision page:

  1. Select Cloud Provider (your choice)
  2. Select Application (Node.js Multi-Process)
  3. Select Datacenter with nearest location
  4. Add Application Name
  5. Add Server Name
  6. Select Server size depending on needs (for Node.js build minimum recommended size is 2-4GB)

Launch Node.js Multi-Process Application

Click on Launch button and proceed with the payment process (trial or payment).

Once payment is completed, server with Node.js app provisioning will be initiated.

Wait for a while; it will take 5-7 minutes to create your server, configure and deploy a high-performance web stack.

By default, on a new server you will get the following stack versions:

  • Node > 20.X
  • npm > 10.X
  • nvm (latest)
  • MariaDB > 10.6 (optional)

On KloudBean, multi-process Node.js applications are deployed with PM2 (Process Manager 2), a production-ready process manager for Node.js applications that allows you to keep applications alive forever, reload them without downtime, and facilitate common system admin tasks.

Accessing Application Administration

Once your server is ready, in order to access your Node.js app, select "Apps" from the header menu to go to the Applications page.

On this page, you will see your application in active status.

Application Status

Click on it to navigate to "Application Administration" > "Access" section.

On this section, you will see:

  1. Application default access URL
  2. Server public address to point your custom domain to it

Application Access

Deploying Your Code Via Git

The next step is to deploy your code.

In order to deploy your code, navigate to the "Code Delivery" tab.

Here, on the first tab → "Git deployment":

  1. Select your preferred "Git Connection Mode"
  2. Connect GitHub using OAuth or copy the SSH public key and add it to your SCM provider (GitHub, GitLab, Bitbucket)

Enable Git Integration

  1. Copy your repo URL and add it here in "Git Repository URL", select branch and "Clone Repository"

Clone Repository

In this example, we're going to deploy an example Node.js app:

[email protected]:jack-kloudbean/node-backend-api.git

Read the detailed guide on connecting Git.

Once the repo is cloned, the next step is to update "Runtime Configurations".

Update Runtime Configurations

Once the repository is cloned, review and update the Node runtime configurations before starting deployment.

Node.js Single-Process Deploy Step 3

Configure the following fields based on your application requirements:

  • Port: The port KloudBean has assigned to your application. Your Node.js app must listen on this port, either directly in your code or through an environment variable such as PORT.
  • Node Version: Select the appropriate Node.js version from the dropdown. Choose the version that matches your project's runtime requirements.
  • Install Command: The command used to install project dependencies. The default command is npm install. Depending on your project, you can also use commands like npm ci, npm install --production, or npm install --legacy-peer-deps.
  • Build Command: The command used to build your application before deployment. For example, if your project is written in TypeScript or uses a framework that requires compilation, you can use a command like npm run build. If your application does not need a build step, you can leave this field blank.
  • PM2 process configuration: This is the bean.config.json file used by KloudBean to run your app with PM2. It is functionally equivalent to a standard PM2 ecosystem.config.js/json configuration.
    • If you already use PM2 locally, copy your existing process definition and adapt paths/commands for the server environment.
    • Common fields you usually customize:
      • name: Process name shown in PM2.
      • script: Entry file to run (for example server.js).
      • instances and exec_mode: Number of processes and mode (cluster or fork).
      • env: Runtime environment variables (for example NODE_ENV=production).
      • Optional reliability fields such as max_memory_restart, autorestart, and restart_delay.
    • After updating bean.config.json, save it and run Pull & Deploy again so PM2 picks up the latest process settings.

Once these configurations are finalized, click the "Pull & Deploy" button to initiate the deployment process.

When you click "Pull & Deploy", KloudBean will initiate the build process automatically by doing the following at the backend:

  • Take latest repo pull
  • Enabling bean.conf for configuration like Node version, app source directory, and build command
  • Setting required Node version
  • Installing packages
  • Making build
  • Deploying it to web root directory

Adding Environment (.env) File

If you need to add or update .env file, you can do it from UI or using File Manager or optionally using shell.

  1. Navigate to the " Runtime Configuration" section and click the "Environment Variables" button to add your vars.

Node.js Single-Process Env Step 1

It will open variables key/value editor. Add your required environment variables. Like in this case, I'm going to add environment variables:

APP_URL=https://nodejs-232200304.kloudbeansite.com
DB_HOST=localhost
DB_NAME=kb_ms3u701nun
DB_USERNAME=kb_ms3u701nun
DB_PASSWORD=31vYF9Dc65gHbV742m
  1. Select Paste .env Content tab and paste your .env file content. You can also manually add key/value pair. Node.js Single-Process Env Step 2
  2. Once added, click Convert to Key/Value, It will convert it to your key/value. Node.js Single-Process Env Step 2
  3. Once updated, click on the "Save Variables" button of the editor, and it will be saved.

Env file path: This path represent there .env file will be saved. If you have any subdirectory (custom app root directory) then .env will be saved in that path.

After saving this, now when you run Build by CI/CD or by manually triggering "Pull & Deploy", your build process will start.

In order to get database access credentials, read the detailed guide on Viewing Database Credentials.

View Build and Deployment Logs

Once deployment process started, you will be able to see its progress in Build & Deployment History section.

Click on the deployment, it will open deployment detail along with live logs.

Node.js Single-Process Deploy Step 4

Once your application is started, you can access it from the access URL:

"Application Administration" → Access → Access URL

If you are seeing 503, that means your application is not up and has some errors.

In order to view application logs:

  • You can view logs using File Manager
  • Or by SSH into the server

Go to directory: /home/admin/hosted-sites/<app_system_user>/app-logs

note

Important: It is important to check your application logs if your site is responding with a 503 gateway error. It shows that the application is not running.

In this directory, application logs are being added in the following log files:

  • app.info.log → information logs
  • app.error.log → error logs

You can open these files using File Manager to view the errors.

Restarting Node Application

If you want to restart your Node application, click "Pull & Deploy". It will build and deploy and will also restart your application.

note

With each deployment, the application also gets restarted. If you need to just restart it, you can run a build from "Pull & Deploy" or using the ADM tool.

Deployment Using ADM Tool

Application Deployment Manager (ADM) is one of KloudBean's features that enables you to deploy your app quickly by just executing one command. It supports all Node.js and Python-based applications.

In order to perform deployment using the ADM tool, you have to access your server using shell.

Read the detailed guide on how to SSH server on KloudBean.

Once you are connected to the server, run the following ADM command:

sudo adm

or

sudo adm <app_system_user>

→ to directly execute for the required application.

ADM Command

If you run this command without app_system_user, then you will have to select the app by providing its number in the prompt and click hit enter.

It will start the deployment process with the logs and progress details on the shell screen.

ADM Deployment

note

Information: While executing deployment through ADM, you will see the port as well to get to know on which port the app is running.

Managing PM2 Using Commands

While your Node app is started successfully with PM2 or may be failing, you can control PM2 using the following PM2 commands:

sudo -u <app_system_user> pm2 status       # to check processes status
sudo -u <app_system_user> pm2 restart app # to restart process app
sudo -u <app_system_user> pm2 stop api # to stop process api
sudo -u <app_system_user> pm2 logs # to view logs
sudo -u <app_system_user> pm2 reload app # to reload process app (zero-downtime)
sudo -u <app_system_user> pm2 delete app # to delete process app
sudo -u <app_system_user> pm2 monit # to monitor processes
note

You can run other PM2-related commands, but make sure to add the correct user with it: -u <app_system_user>

Once your application is live, you can access it using the app access URL followed by each app process name.

In this example:

  • apphttps://<app-access-url>/app
  • apihttps://<app-access-url>/api

Next Steps