Quick Start Guide: How To Install Node js Project In Runcloud

preview for using nodejs application in runcloud nginx server

How to install Nodejs application in RunCloud?

Welcome to our quick start guide on how to install a Node.js project in Runcloud. Node.js is a popular platform for building web applications, and Runcloud is a powerful tool that simplifies the process of deploying and managing Node.js projects on the cloud.

If you are looking for steps to install NodeJs on RunCloud OpenLiteSpeed server refer here : How to create Nodejs app in OpenLiteSpeed(OLS) RunCloud? (linuxtutorialz.co.uk)

Also, you can find steps to upgrade Node version here : Upgrading Node Version on Ubuntu Server: Step-by-Step Guide (linuxtutorialz.co.uk)


Introduction

In this guide, we will walk you through the steps of setting up a Node.js project in Runcloud, including creating a server, installing the required dependencies, and deploying the project. We will also provide some tips and best practices for managing your Node.js project in Runcloud.

With this guide, you will be able to quickly and easily set up a Node.js project in Runcloud and start building your web application. Let's get started!

Step 1

First, we need to create a web application with empty web application and "Native Nginx + custom config" option. We are using custom config type since it's not using PHP and for PHP web applications it's better use the Hybrid or native type.
Creating web application as empty
Enter web application details

Step 2

Now, we can SSH or SFTP to the web application root folder to update files. Please make sure to delete the index.html placed by RunCloud(Since we are copying content to current webapp root folder instead of creating one more folder(like the-example-app.nodejs), for that we need a empty folder). For this case, I'm using below git repo sample. Refer : https://github.com/contentful/the-example-app.nodejs

git clone https://github.com/contentful/the-example-app.nodejs.git .
npm install
Now, we can test if this is working as expected but the socket is yet to be running so we must run below command.

npm run start:dev

Step 3

However, we will not see the expected result since we have not yet done the proxy configuration. Go to your web application >> create Nginx congiguration as below

proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
Needed Nginx configurations
Please make sure it is added under location.root type. To test websocket working, we can use

curl http://localhost:3000
This will give us some response with website content. Now, we can call our main domain and it should be loading fine. However, this response will turn into 502 if we exit from shell running "npm run start:dev" as there will not be any service to listen on 3000 port. 

I have seen most people going with pm2 but I always use the supervisor since it's already installed in RunCloud server. Please add it as below
example of a configured supervisor
Please make sure we have selected correct user, directory and vendor binary.

Now, the port will be listening all the time and your website should be working fine.
Website loading fine
Please let me know in comments if you are facing any issue.



Conclusion

In conclusion, the quick start guide on how to install Node.js project in Runcloud provides a simple and easy to follow steps for beginners to set up their Node.js project in the cloud. With the help of Runcloud, users can easily manage their Node.js project, deploy applications, and monitor their performance. By following the guide, users can quickly set up their Node.js project and start working on their project without any hassle.


Comments

  1. What about Webapp on Litespeed Stack?

    ReplyDelete
    Replies
    1. Check it here : https://linuxandruncloud.blogspot.com/2022/09/how-to-create-nodejs-application-in.html

      Delete
  2. what if i run react?
    what the supervisor will be?

    ReplyDelete

Post a Comment