I wrote a step-by-step guide to deploy the HoneyComb node using Docker. Many people found it very useful and were able to run a node without any technical expertise. A few people approached me asking if there is a possibility to run the node without using Docker as they are not familiar with Docker. They also expressed challenges when they wanted to run multiple instances of the node.
This guide will be useful for people who would like to run the HoneyComb node (SPK claim node) without using docker. We are going to use pm2 to run the node in the background. Pm2 is a utility to run node apps in the background. It comes with lot more facilities to monitor the node, automatic restart, etc. Let's go step by step.
Step 1: Prerequisites and Server setup
You can refer to my previous article for this information. It is pretty much the same. There are no changes as far as I know. We can jump to the next step.
Step 2: Install Nodejs and Pm2
Pm2 is a package inside Nodejs, so it is mandatory to install node js. Even in the docker approach, the application was running only with the help of Nodejs but Docker would handle installing it and running it inside the container. Now that we are going to run it directly, we have to first install nodejs.
The documentation recommends from version 10 to version 15 but I did install version 16 and it appears to be fine. For Ubuntu, I usually go to the below link and grab the commands to download and install it.
https://github.com/nodesource/distributions/blob/master/README.md
It should be pretty much straightforward. If you are having trouble installing Nodejs, please leave a comment in this article and I will elaborate on this step.
After installing nodejs, we can check the version of nodejs and npm using the below command.
node -v
npm -v
Now the next task is to install pm2. The below command can be used to install pm2.
npm install -g pm2
This command will install pm2 globally. This means we will be able to use pm2 not only for this node js application but also for any node application we would like to deploy.
Step 3: Getting the latest code and updating the .env file
After cloning the latest code from the repository, we have to run the below command to install the packages. This command will install all the dependencies that are required for the node.
npm install
Updating the .env file is also similar to what we do with docker. The procedure is the same. You can refer to the previous documentation to update the environment file.
Step 4: Starting the application
This part is a little different. We are going to be using pm2 to run the application. The below command can be used to start the application.
pm2 start index.js --name spkcc --time
This command will start the node. We can also run the node without using pm2 using the below command.
node index.js
But the problem is, when we close the console, the application will stop. That is the reason why we have to run the application using a process manager like Pm2.
Final Optional steps
With this, the node should be successfully running. Whenever there is an update, it is also easy to update the code and run the updated version of the node. The following commands will be useful for that.
git pull
pm2 restart spkcc
This basically pulls the latest code and restarts the node. You can either do it manually or schedule these commands or automate this command using a shell script.
If you like what I'm doing on Hive, you can vote me as a witness with the links below.
|
|
|
|
|
|
Posted with STEMGeeks