Reputation: 37
I have already developed an Application in Nodejs. It is running quite well on the local machine. But the problem rises while I am trying to deploy the Application as a Back-end App on a Linux VPS.
I have installed the Nodejs on Linux VPS already and already added PM2 module to run the Application. But it is showing error while executing the command "PM@ start index.js".
At the time of looking for the error I found that the version of Node that I have installed is 6.14 which is not compatible for PM2 module. Even if I also tried to upgrade the version of Node along with npm but old version name is showing up.
Please advice how to configure a Linux VPS to run a nodejs application.
Upvotes: 0
Views: 1921
Reputation: 306
My advice would be to use the Node Version Manager for installing and managing Node versions in Linux as some versions of Linux have very old versions of Nodejs in their package repositories. If you have node already installed, please uninstall it using your package manager on your Linux VPS. If you are using Ubuntu based VPS, it should be possible using the command:
sudo apt-get purge nodejs
This is how you install the Node Version Manager:
https://github.com/nvm-sh/nvm#installing-and-updating
You will need curl or wget before you can install Nodejs. So you will need to do the following:
sudo apt-get install curl
After that, you run the following command to install the Node Version Manager (nvm).
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
Now, to install the latest version of NodeJs using NVM, it is a simple command:
nvm install node
If you prefer a specific version of NodeJs, you can install it using a command:
nvm install 14.8.0
You can check to see if NodeJs is successfully installed by running the following command which will return the version of NodeJs:
node --version
Upvotes: 0
Reputation: 1380
If you're using Express.js, you need to point it to bin/www, like below.
pm2 start bin/www
You also need to add --node-args="-r esm" if you're using ESM.
pm2 start bin/www --node-args="-r esm"
Upvotes: 1