RunCloud is the easiest way to start hosting your web applications online. If you’re using RunCloud to manage your servers, then you’re not limited to any particular tech stack or technology – RunCloud provides you the freedom to configure your server however you want.
In this tutorial, we’ll explain exactly how to install NodeJS on your server – and use RunCloud to manage your node applications.
Installing NodeJS on RunCloud Server
Before you install NodeJS, you need to find out what server type you’re using. The steps to install and configure NodeJS are slightly different for Nginx, OpenLiteSpeed, and Docker servers.
Additionally, you need to enable SSH access into your server, and log in with necessary privileges.
Step 1: Install GPG keys and prerequisite packages
After logging in to your server, execute the following commands in the terminal window to install and configure the prerequisites for installing the NodeJs on your server:
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
Step 2: Create Debian Repo
Before installing node, you need to specify the version that you want to install. Execute the following commands to set up the Debian repository on your server:
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
Note: The above commands assume that you want to install Node 20, which is the latest LTS version at the time of writing. If you want to install a different version, such as Node 18 then just replace NODE_MAJOR=20
with NODE_MAJOR=18
in the first line of above code snippet.
Step 3: Install NodeJS
After configuring the node version, you can go ahead and execute the following commands to install Node on your server:
sudo apt-get update
sudo apt-get install nodejs -y
node -v
Once the installation is complete, you should be able to start using NodeJs right away without any need to restart your server.
Deploying a Node App on RunCloud
The process of deploying a Node app is slightly different for each server stack. Make sure you follow the steps corresponding to your server type after you complete the steps below:
First, deploy an empty web application on your RunCloud server. Give it a descriptive name and specify the user account, domain name, and backup configuration.
For the server stack, you can select Native Nginx and leave the stack mode to Production. Finally, click on the Deploy application button to create an empty app.
After creating the empty application, you need to add your application to the root directory of your project. In this example, we have created a simple ‘hello world’ application using NodeJS.
After adding your application files, start your node server – the exact command for this will vary depending on the framework and libraries that you are using.
For Nginx
Once your server is up and running, you will need to create a proxy so that Nginx redirects the traffic to your web application. In the above example, our server was running on port 3000
. Note down the port number of your application, and then navigate to the Nginx Config menu in the RunCloud dashboard.
Click the “Create Config” button, and follow the steps below:
- For the “Type” option, make sure to select the value
location.root
. - For the “Config Name” option, you can use any value such as
myApplication
. - For “Config Content” textarea, copy and paste the text below. Make sure to change
XXXX
with the port number that we noted down earlier.
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:XXXX;
Click “Run and Debug” to see if there are any issues with this custom config. If you don’t get any errors, click the “Save Config” button to finish it. Now you should be able to access your application from the internet.
For OpenLiteSpeed
On OLS servers, once your application is up and running, you can quickly create a proxy to redirect traffic. Navigate to the LiteSpeed Config menu and scroll down until you see the configuration file.
We will need to edit a few lines in this file. Firstly, note down the name of the extprocessor block – we will use this later.
Next, disable the existing configuration by adding # before the type and address line.
After that, add the following lines below the commented lines. Don’t forget to change xxxx with the port number that we noted down earlier.
type proxy
address localhost:xxxx
At this stage, your configuration file should look like this:
Next, scroll down and add the following code snippet to your configuration file. Be careful not to paste it in the middle of an existing config block.
Replace the <my-app>
with the name of the extprocessor that we noted down earlier.
context / {
type proxy
handler <my-app>
addDefaultCharset off
}
At this point, your config file will look something like this:
Click on “Update Config” to save the settings. Now you should be able to access your web application directly from the internet.
It is clear that RunCloud is a flexible platform to deploy and manage your web applications. In this post, we have explained how to install a basic application on your server but that’s not all RunCloud can do. Check out the following articles and learn how to use RunCloud to its fullest potential: