Weird PM2 - NodeJS Version Behaviour - node.js

I am experiencing a weird bug with NodeJS's File System module, where the remove directory function is asking for a callback, despite there being one. Having a look, it turns out this is a bug with NodeJS that was resolved in later releases
I tried to update the server's nodeJS version, except, as NVM was reporting, it was already fully updated.
Using the pm2 show APP_NAME command, I determined that PM2 was running the app in NodeJS v10.19.0, and all steps to update it were fruitless.
So how can I fix this?
Notable Details:
DigitalOcean Ubuntu 20 Droplet
PM2 Installed
NodeJS v16.15.1
NVM Installed

In order to resolve this issue, I had to kill the current in memory version of PM2, and go to the following directory as root:
~/.nvm/versions/node/v16.15.1/bin in there is a pm2 executable.
In order to get the application to run in Node v16.15.1, I had to run the following command ~/.nvm/versions/node/v16.15.1/bin/pm2 start index.js --name APP_NAME, and then and only then did it run the application properly.

Related

PM2 Process Manager is not showing the actual version from each project package.json version but NVM version number

I'm running PM2 list on MacOS, and those projects node are running of the nvm managed node version. by right the expectation on the versioning column it should be showing individual node process version based on their package.json version number respectively.
but it's showing the version of nvm (node version manager). which is odd. Anyone has a clue or is this a bug from PM2 ? It happens for the couple of teammate who are working on MacOS either.
I finally understand the logic how pm2 works.
the current setup node was managed by nvm and pm2 is installed globally inside the node version.
when those process above was started by using the following style:
{
...
script: 'npm',
args: 'run start:auth'
...
}
in the pm2 config.js (start script), it indirectly ask PM2 to refer to the nvm folder, to use the npm there. at such when we inspect the process by invoking pm2 info auth it shows this line, this gave us the hint, pm2 would read the package.json resides in the ~/.nvm folder, thus it becomes the version from nvm.
Therefore the mystery is resolved.
NOTE: PM2 would read the first available package.json from the repository root, or somewhere available within the script path (e.g. when we do the pm2 info <process>). with that said, in normal circumstance we only use pm2 in a production environment, and we tend to use it to start the actual *.js script, and it would process the package.json correctly without any issues.

How to run asp.net core application using pm2 on linux server

I have updated my asp.net core API over linux server using kestrel, I want to run the core application using pm2. Let me know if any buddy has already done this kind of task.
What I have tried is:
I Installed the pm2 on my linux server (not globally). It installed successfully but when I'm trying to run the code using pm2, I am getting error pm2, command not found
I tried to install the pm2 globally but getting write access issue in node modules some where but I can't give global write access.
Thanks in advance for your help :)
pm2, command not found means the binary is not found cause it is most probably missing in your PATH variable. The path differs whether you install it globally or not - see pm2-command-not-found how to figure out the path and how to add it to your PATH variable.
When not installed globally, the binaries are under ~\node_modules. This you have to add the actual binary path e.g. ~/node_modules/pm2/bin to the PATH variable or you call it directly using ~/node_modules/pm2/bin/pm2
For the installation problem mentioned above, run the installation as sudo npm install -g pm2

How to check which user Phusion Passenger chooses to run node.js?

What is the best practice for using Phusion Passenger with a version of node installed my nvm?
In this tutorial on using Passenger to run a Meteor app, I read:
[Y]our Meteor application is run as ... the owner of the
main.js file (when deploying a Meteor bundle), unless you configure it
otherwise. Of course you still have to make sure that each of your
applications is owned by another user.
Meteor 1.6 works with Node.js v8.8.1, so I have used nvm to install node. I created a special meteor user to run the nvm installation of node and nvm. Node was therefore installed at /home/meteor/.nvm/versions/node/v8.8.1/bin/node, and /home/meteor/.nvm/versions/node/v8.8.1/bin/ was added to the $PATH variable for my meteor user. As a result, calling node -v as the meteor user showed that v8.8.1 was installed and accessible.
I followed this tutorial to deploy my Meteor app to my server.
As the meteor user from within the bundle/programs/server directory, I ran npm install --production. I made meteor the owner of everthing inside bundle/.
I had expected that Passenger would launch node as the meteor user, and that everything would run smoothly. Instead, Passenger showed a useful alert page, apologising that "something went wrong".
To work around this, I created a symlink at /usr/bin/node to point at /home/meteor/.nvm/versions/node/v8.8.1/bin/node, and now Passenger was happy to launch the bundled app.
This suggests to me that Passenger was not running main.js as the meteor user. Or is there another reason why the meteor user was not able to see its own version of node?
The quote above suggests that it is possible to configure which user Passenger uses. How do I do that?
In a nutshell: what is the official Passenger method for working with a version of node installed by nvm?
You'll want to set the version of node to the full path to the nvm node: https://www.phusionpassenger.com/library/config/standalone/reference/#--nodejs-nodejs
As for the user-switching, you can set the log-level to 7 (https://www.phusionpassenger.com/library/config/standalone/reference/#--log-level-log_level) in order to debug that and either go through the startup logs yourself or post them here.

Node module missing error when script tries to restart

I am running CentOS Linux release 7.1.1503 (Core) and I frequently run into a problem of missing node modules.
Here are some paths I printed on the console:
which npm
/root/.nvm/versions/node/v8.2.1/bin/npm
which node
/root/.nvm/versions/node/v8.2.1/bin/node
which forever
/usr/local/bin/forever
Now, when I start the script with forever it runs. Sometimes in the midnight, when I just verify if all the scripts are running, many are failing and the error is something like:
I have to go and install the node module. What could possibly be the reason for this? Could it be some permission issue?
Check if you have fs-extra installed at the directory you working or globally (if not - just run npm install fs-extra)
If you are going to work with AWS.S3 - check credentials permissions (for example aws s3 ls - you should see list of available buckets)

How to start Node.js service automatically on CENTOS 6.7?

I have two servers running nodejs applications. I did some setting with the first one before. After that setting, when I start the command line, if I run node command, I see the service is running.
But I do not remember what I did. So in my second server, anytime I restart command line session, when I type node I get -bash: node: command not found.
Could anyone remind me please?
NOTE: Please don't tell me this is duplicate. Search for keywords "start, node service, automatically, etc." most of them tell about the use of 'forever'. I know forever (gdi), mine is a lot more stupid question and I don't know the correct terminology just yet.
I would suggest using pm2 or forever
For pm2 do the following
Install it using
npm install pm2 -g
-g installs it globally. Then do following
pm2 start app.js --name="api"
Once that is done, you can do pm2 list to view all running services as follows
Make pm2 start at boot time
pm2 startup
This will automatically start your node.js app.
Works for my 4 apps that are in production.
Hope this helps.

Resources