''pm2' is not recognized as an internal command with volta install - node.js

I install volta as node version handler and when I run pm2 status/start/stop in PowerShell or cmd, there is
'pm2' is not recognized as an internal command' error.
I know that I should install pm2 as global but run npm i -g pm2 it is not working and have same error. Anybody has any idea?

by this answer of Volta and global npm package I just run volta install pm2 instead of npm i -g pm2 and set Volta/bin in environment variable of windows. in Global installs done right said:
By running volta install mocha, you let Volta know that you want mocha to be available everywhere in your terminal

Related

npm global install not recognized (gulp)

I'm trying to use gulp for the first time.
Following instructions online, I installed it globally as well as locally, but I still get the
'gulp' is not recognized as an internal or external command[...] error. When using PowerShell instead of cmd the error is the term 'gulp' is not recognized as the name of a cmdlet, function, script file[...]
I've tried:
installing gulp-cli in addition to gulp
adding / changing PATH variables
restarting my PC
running npm install -g npm#latest to make sure npm is up-to-date
I'm stumped. On top of all that, I have other npm packages installed globally that work fine.
Edit: I fixed this by adding npm to my PATH environment variable. I had been adding it to NODE_PATH, which doesn't work for CLI use.
"Global install" with the -g flag basically means you install the command provided with the package.
To globally install gulp:
npm install gulp -g
You can add the gulp script in the package.json file and run the gulp command using npm.
Ex:
gulp task name : helloTest
Add below code in package.json:
"scripts": {
"helloTest": "gulp helloTest",
}
And now type below command in terminal:
npm run helloTest

Cannot install pm2 in OS 10.15.5

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.

nodemon bin/www works, nodemon app doesn't and throws error

When I run nodemon bin/www inside my app, it works perfectly, when I try to run nodemon app, it throws this error:
'\"node .\bin\www\"' is not recognized as an internal or external command,
operable program or batch file.
I believe this happened after I received a notification from nodemon today to run npm install -g nodemon to update the nodemon library, after the installation, I got this error:
Please try running this command again as root/Administrator.
I tried to run the cmd as administrator, again, the same problem. Any solution?
step 1: run npm install -g nodemon
step 2: verify installation npm list -g nodemon
Now you can run the app by two ways
nodemon ./server.js localhost 8080
Any output from this script is prefixed with [nodemon], otherwise all output from your application, errors included, will be echoed out as expected.
2nd just type nodemon
If you have a package.json file for your app, you can omit the main script entirely and nodemon will read the package.json for the main property and use that value as the app.
With a local installation, nodemon will not be available in your system path. Instead, the local installation of nodemon can be run by calling it from within an npm script (such as npm start) or using npx nodemon.
or
It turns out that you don’t have to run the command again as
Administrator, and doing so won’t fix the problem. Try
npm cache clean first.
check this for more detail
https://www.npmjs.com/package/fixmynode
command against as root administrator
how-to-fix-node-js-npm-permission-problems
I think you are getting this error because you did not install it as a global module. Try to install nodemon using the -g flag.
$ npm install -g nodemon
Install the nodemon module globally using
npm install -g nodemon
Also install the module in the package in your project where the package json is present using
npm install nodemon -save
Check if the nodemon is present in the json list.
Now run the js file using any of the following
nodemon
nodemon app.js
nodemon app
Use the following command line in an windows environment (1st cd to your apps root directory):
nodemon ./bin/www

npm packages not available when installed locally

I am working with npm on a web app and I found an issue when using some packages that requires terminal commands to run such like nodemon and concurrently
I installed it via
sudo npm install --save-dev nodemon
and when I try to use it via:
nodemon ./server.js
I get an error
nodemon command not found
and the same when I used concurrently
I tried also with
sudo npm install --save nodemon
and it doesn't work.
it only work if I installed it globally
sudo npm install -g nodemon
Why I can't use it when install locally?
Note: I can found the executable file at node_modules/.bin
but this following not working as well
node_modules/.bin/nodemon ./server.js
Global packages can be launched directly because they are saved in your PATH directory by default. If you saved a package locally you can see it on node_modules/.bin/ as you mentioned. So there are 2 ways to achieve what you want if you want to run an executable package if installed locally:
You can run it via terminal as ./node_modules/.bin/nodemon yourscript.js
Or via npm scripts in your package.json file, you do this:
{
"scripts": {
"nodemon": "nodemon yourscript.js"
}
}
and execute npm run nodemon.
The 2nd approach works for both packages installed globally or locally.
I prefer installing packages locally, so my other apps won't get affected especially if I'm using different package versions per project.
UPDATE
On npm#5.2.0 onwards, it comes with a binary called npx. So you can run specific packages on the terminal just by npx [package] and it executes either your local or global npm package. In your case it should be something like npx nodemon server.js.
Because it's in your node_modules/.bin folder, not your PATH.
You can either use ./node_modules/.bin/nodemon or $(npm bin)/nodemon to call nodemon.
To run any locally installed npm module (Mocha, Eslint, Nodemon, etc.), you can now use npx. Try npx nodemon server.js.
I also recommend setting main within your package.json to point to the script you want to run (index.js by default), so you could just run npx nodemon or nodemon (if globally installed) and it will know which script to run.
This is because the local node_modules folder is not in your PATH. See the link to the duplicate question for more details.

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.

Resources