Cannot install pm2 in OS 10.15.5 - node.js

Mac os Catalina 10.15.5 / npm version 6.14.5
When I install pm2, it seems that it is being installed without any problem.
But if I run pm2, the terminal only says that command not found.
It's not working at all. It just doesn't start.
I searched through StackOverflow and tried the following solutions.
- npm i -g pm2
- sudo npm install -g pm2
- npm i pm2#latest --no-optional -g --no-shrinkwrap
- sudo npm install pm2 -g --unsafe-perm
All of the above gives me this result.
/Users/myname/.npm-global/bin/pm2 -> /Users/myname/.npm-global/lib/node_modules/pm2/bin/pm2
/Users/myname/.npm-global/bin/pm2-docker -> /Users/myname/.npm-global/lib/node_modules/pm2/bin/pm2-docker
/Users/myname/.npm-global/bin/pm2-dev -> /Users/myname/.npm-global/lib/node_modules/pm2/bin/pm2-dev
/Users/myname/.npm-global/bin/pm2-runtime -> /Users/myname/.npm-global/lib/node_modules/pm2/bin/pm2-runtime
+ pm2#4.4.0
updated 1 package in 4.768s
After this,
If I type pm2 : I get pm2-bash: pm2: command not found
If I type whereis pm2 : it just doesn't do anything at all.
If I type pm2 start index.js in VScode terminal: zsh: command not found: pm2
And there are the files inside of the path(/Users/myname/.npm-global/bin/).
I don't know what the problem is.
Any help or advice will be appreciated.

those who are having the same problem, hope it helps.
After repeating countless uninstall & install of node/npm/pm2 whatsoever and toying around the permissions, I found answer by myself.
Changed default command shell from zsh to bash. (in VScode as well)***
Deleted all the node & npm and installed nvm, and re-installed node via nvm.(npm is automatically installed together).
Installed pm2 with npm.

Related

'express' is not recognized as an internal or external command

I am trying to start an express-generator app but I am getting "express is not recognized an internal or external command. I tried all the below
in windows CMD as administrator:
$ npm install express -g
$ npm install express-generator -g
$ mkdir myApp
$ cd myApp
$ express helloApp
the latest command was supposed to create all the express-generator related files (i.e. routes, models, views, etc.). But I am still getting the same error again and again. Any solutions would be much appreciated.
Since you are using npm < v8.2.0 you need to install it globally (v8.2.0 allows you to use npx). From their documentation:
$ npm install -g express-generator
$ express --view=pug myApp
You can change the view parameter or even exclude it. This is how I always do it and I just tested it to confirm it works for me although I am using a different version of npm and node than you are.
try this.
npm cache clear --force
$ npm install -g express-generator
$ mkdir myApp
$ cd myApp
$ express helloApp `
remember if you are installing globally you need to use sudo for linux and mac, and powershell or admin cmd to run the code. eg
$ sudo npm install -g express-generator
i solved the above error by uninstalling node js(v10.16.3) and reinstalling the current version (v12.12.0) ....followed by the known commands:
npm install express -g
npm install express-generator -g
express project_folder_name
honestly till now i couldn't find any reason for what caused this...but i suppose it was something related to my node_modules directory....
thanks Dillan and Ani for your kind help...your suggestions helped a lot....thanks :)
One other possibility - I was unable to use express-generator in vscode. I tried to use it separately in both cmd and powershell. It worked using cmd, but not powershell. Modify vscode to make cmd the default terminal and you're good!

How to install node/npm so that 'sudo npm' works on an ec2 instance?

Answer: Follow the steps in this link
http://iconof.com/blog/how-to-install-setup-node-js-on-amazon-aws-ec2-complete-guide/
I am running ubuntu on an ec2 instance and need to sudo npm install something. I am given the error that sudo npm is not recognized.
There is a previous thread that is 7 years old. On EC2: sudo node command not found, but node without sudo is ok I tried every solution there and nothing worked.
I think the problem is using NVM to install npm and node. How can I install these so that they are compatible with sudo? Thanks!
You can run the following command
sudo yum install nodejs npm --enablerepo=epel
For more, you can also install using the following link also: https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html
Second Approach:
Install NPM
git clone https://github.com/isaacs/npm.git
cd npm
sudo env PATH=$HOME/local/node/bin:$PATH make install
Now you can install npm packages and run javascript node files as usual!
sudo npm install forever -g
sudo npm install express -g
Resource Link: http://www.wisdomofjim.com/blog/how-to-install-node-and-npm-on-an-ec2-server
You can use NVM. You can follow this link which gives proper steps to install node on ec2 instance.
I dont know if my problem is the same as yours (i think is similar), but i tried to run "sudo npm install" on a amazon linux ec2 machine and it gave me the "sudo: npm: command not found" type of problem.
I followed the instructions recommended by AWS to install node and NPM (https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html).
I solve this by changing the owner and group of the directory and files (package.json and package-lock.json):
chown ec2-user:ec2-user nameDir
and then i run npm install again. It worked!

Nodemon installed but can't be found

I've tried uninstalling and and reinstalling nodemon several times both locally and globally with:
npm install -g nodemon
(tried it both with and without sudo)
and it seems to install no problem, and gives me:
/usr/local/bin/bin/nodemon -> /usr/local/bin/lib/node_modules/nodemon/bin/nodemon.js
/usr/local/bin/lib
└── nodemon#1.11.0
but whenever I run
nodemon server.js
in my app, I get;
-bash: nodemon: command not found
Like I mentioned, I've tried the same process but installing locally to my app dependancies, but it doesn't seem to make a difference. What's going on here? I followed the same process on a different machine, and it worked no problem.
Googling around, I came across some posts that mentioned changing/adding the PATH? But it's not clear to me if that's or the problem or what that means.
Also, other globally installed npm modules run just fine
nodemon is not being found by bash.
Edit your ~/.bash_profile file and add:
PATH=$PATH:/usr/local/bin/bin/
Start a new shell to see it work, or run source ~/.bash_profile to have it apply to the current session.
Instead of using sudo switched as root and then just run:
$ npm install -g nodemon
sudo su -
export PATH=$PATH:/home/USER/npm
npm install -g --force nodemon
# THESE LINES + START FROM A NEW TERMINAL...
# IN MY CASE
npm install -g --force node-inspector
# TOO

How to start the node.js application using pm2

I have installed pm2 module using the following command:
npm install pm2#latest
Then I tried to start my test application using pm2 as follows:
$ pm2 start test.js
It throws the following error:
'pm2' is not recognized as an internal or external command
Do i need to set environment variable for pm2?
You need to install PM2 globally via npm install --global pm2#latest and if you want to use the local version, try ./node_modules/.bin/pm2 start test.js.
After installing PM2, we may need to add following value to path variable under Environment Variables
C:\Users\USERNAME\AppData\Roaming\npm
After adding, reopen the command prompt.
You might installed the pm2 locally instead of global scope, this is due to missing -g parameter in your installation command.
npm install -g pm2
or
yan add -g pm2
If you tried npm install pm2 then the module will install locally to the app that you are currently developing from there you can invoke the pm2 using,
./node_modules/pm2/bin/pm2 start index.js
But it won't mostly work on windows. Try to use the global install option.
You are getting the same error after global install option then add the npm path in your environment variables.

Nodemon stopped working

I use nodemon to work with node.js. All is fine. Today I typed nodemon app.js and it doesn't know the command.
I reinstalled with npm install -g nodemon.
It reinstalled without any error.
It still doesn't work.
under:
user\AppData\Roaming\npm
I removed all files depending nodemon.
Again I reinstalled but it still doesnt know the command. What happend and what to do?
Windows 8.1
Open and run the command line window as administrator and run the command npm install -g nodemon

Resources