Nodemon installed but can't be found - node.js

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

Related

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.

npm command 'serve ' not found, although it is installed

I have installed serve with npm as "npm install serve -g" and also with yarn "yarn global add serve", but when I try to run "serve -s build" it says that "Command 'serve' not found.
You should not install the packages globally.Try to do the following-
npm uninstall -g serve
npm i -S serve
Let me know if this works.
I had same problem too and this helped me to fix it so try this after installing serve;
npx serve -s build
or
npx serve -s build -p 8000
(8000 = it depends by your choice)
I don't know why but this worked for me
None of these above answers worked for me, so this is what works for me :
sudo su
npm install -g serve
Installing as root helps globally installing serve
Make sure to have this in your .bashrc or .zshrc
if you're using Yarn:
export PATH="$PATH:$(yarn global bin)"
if you're using NPM:
export PATH="$(npm bin -g):$PATH"
So that the shell would know where to look for executables such as serve, npx, live-server etc that are installed globally.
Make sure to reload your shell config:
source ~/.bashrc // or ~/.zshrc
If anyone still gets the problem, try this:
npm uninstall -g serve
npm i -S serve
yarn global add serve
I faced the same problem, what I did was run the command yarn serve -s build
If you got it installed with npm then you can just add npm before the suggested command

angular-cli installs but ng command is not recognized

It happens that when I install angular cli, it gets stuck at
this point
I have looked for any solution , install/uninstall node.js and tried to use different versions of node and npm with no success.
EDIT: After uninstalling node.js, erasing npm folder in appdata, and reinstalling again, it installs but it does not recognize the ng command as shown here
It seems it is a path issue. This solution helped me fix it on macOs High Sierra.
npm install -g #angular/cli
Make sure the ng path is correct
cd ~/npm-global/bin
ls and make sure ng exists
create .bashrc file on your home directory
touch ~/.bashrc
vim ~/.bashrc
Add ng as alias
press i (enables edit mode) then type in the following
alias ng="~/npm-global/bin/ng" (or wherever your ng directory is)
press esc (to get out of edit mode) then :wq (in vim will save)
Temporarily Update .bashrc reference
Your terminal wont take bash updates until a restart but the following command will let you use the updates during the terminal session:
source ~/.bashrc
Check that ng works
ng --version
Found it from https://github.com/angular/angular-cli/issues/5021
May be try using ng commands with node.js cli (Node.js command prompt). It might work. I'd the same problem Here.
It happens that your node.js and angular visions are not compatible.
After the install and remove all the node files from on your pc.
then try these commands.
Install node.js package manager stable version.
After the install you run npm install
npm install -g #angular/cli 04 ng new <project name>
cd <your project location>
ng serve
(If it's still not working, again npm install and ng serve)
If this is still not working, provide a sample of the .json file in your question.

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

I can´t install nodemon globally, "nodemon" not recognized

I want to use nodemon for monitoring my node.js app's, then I execute the next line command:
npm install -g nodemon
or
npm install nodemon -g
When I move to my app folder and try to to
nodemon app.js
The system tells to the next:
"nodemon 'is not recognized as an internal or external command, program or batch file.
Since node prefix is not in the PATH ENV variable , any of the globally installed modules are not getting recognized.
Please try this.
Open cmd prompt
npm config get prefix
append the resulting path to PATH env variable.
Now you should be able to run nodemon from any location.
This is what i have done on my local machine
C:\>npm config get prefix
C:\Users\username\AppData\Roaming\npm
C:\>set PATH=%PATH%;C:\Users\username\AppData\Roaming\npm;
C:\>nodemon
31 Jul 22:30:29 - [nodemon] v0.7.8
31 Jul 22:30:29 - [nodemon] to restart at any time, enter `rs`
31 Jul 22:30:29 - [nodemon] watching: C:\
31 Jul 22:30:29 - [nodemon] starting `node `
^CTerminate batch job (Y/N)? Y
I also got same error as you with this command:
$ sudo npm install -g nodemon
I just really switched as "root" and then just ran:
$ npm install -g nodemon
I think npm has a bug to not work with sudo, but it works fine when you are really "root".
Single line solution
In terminal
npm install -g --force nodemon
There is a problem with integrated terminal of vs code. when I try in external terminal nodemon works. But in integrated terminal, it gives bash: nodemon: command not found error.
so here is my solution
install nodemon as development dependency
npm install --save-dev nodemon
and change package.json of the project
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"nodemon": "./node_modules/.bin/nodemon"
},
to run nodemon type into terminal in project folder
npm run nodemon
Mine was I went to Control Panel and Repair the NodeJS app and tried to install again with npm install -g nodemon and now it works. Maybe you mixed up or something with Node.
check out here :-
npm install -g nodemon
and then run
$nodemon server.js
You won't need to install nodemon anymore, since Nodejs has finally introduced its --watch feature which restarts the process when an imported file is changed.
node --watch index.js
https://nodejs.org/en/blog/release/v18.11.0/
Linux users: I would highly suggest not using sudo or root user to install npm packages. This could become a security problem especially on a production system. I would also suggest not trying to hack permissions as I have hosed an Ubuntu system by not reading the warning on the npmjs procedure.
It would be better to configure npm to use a folder owned by the current user. Simplest approach
wget https://raw.githubusercontent.com/pcnate/npm-configure/master/add-npm-global.sh -q -O - | bash
npm install -g nodemon
Or get the code script on github to see how it works
See details on the npmjs website
On Windows, I was having issues installing nodemon directly from the Command line. Downloaded Cygwin and I was able to npm install nodemon instantly.
You can add path to node packages in System Path variable.
Add "C:\Users\UserName\AppData\Roaming\npm".
Even after adding path to System Path variable it did not work for me using nodemon. Then i used npm run serve to run the server. now it is up and running. Btw i am a windows user
This command worked for me.
If your global installation didn't work then install it in your
development dependency.
npm install --save-dev nodemon
Updated
After Path settings we also need to type in the following commands
Set-ExecutionPolicy Unrestricted
what this command enables running scripts on the system
I think some of us can't reach global environments without admin privileges.
If you tried everything and it's still not working, try running VSCode as administrator. It worked out for me.
had the same problem otherwise was just working fine a day ago.
Very simple fix
first check if nodemon exists on your system globally or not
To check
npm list -g --depth=0
If you don't see then install
it npm install -g nodemon (g stands for globally)
If you see it still doesn't work then you need to configure environment variable
I use Windows OS. On Windows navigate to
Control panel>System>Advanced System Settings>Environment Variables>double-click on PATH
Now check if you have this PATH C:\Users\yourUsername\AppData\Roaming\npm
If not, you will see some existing paths, just append to it separating with semicolon. That's it! Worked for me.
For me node was installed in C:..\Roaming\npm and for you if the PATH is different, you will put in whatever applcable.

Resources