I installed node.js and npm to my centOS 7 server. But i have problems with pm2. Actually real problem is i don't have experiences in linux and i don't know how to change path. Here is folder structure.
* bin
* code
* error_docs
* httpdocs
* lib64
* logs
* tmp
* var
* chat(my node.js folder)
* node_modules
* pm2
* sockjs
* server.js
* dev
* etc
* lib
* local
* sbin
* usr
I entered folder by typing cd chat
and installed pm2 with npm install pm2
.
After that I tried use pm2 for my server.js by typing pm2 server.js
server returns "pm2 command not found". I can use node.js without any problem but pm2 not working.
How can i solve this?
PM2 the process manager for Node.js applications. PM2 basically manages applications (run them in the background as a service). So this is how we install PM2 globally with sudo permissions account
The -g option tells npm to install the module globally, so that it's available system-wide. Once this is installed, check the installed path as:
Now, we need to add this path in startup bash script. Add add the following line anywhere in ~/.bashrc file.
Now re-login or source the bash script as follows(so that bash script runs and path is set)
and now it should run. check the status of pm2
It worked for me.
This option helped me:
If you used nvm to install node and npm, install pm2 for normal user.
run as root:
append below code, change NVM_DIR to you normal user's home folder:
at last :
If you install through NPM and it does not work, you can create a symbolic link as well :
After that, you're going to be able to call:
Install PM2 globally and run everything as a root user
You are good to go