nodemon command is not recognized in terminal for node js server - javascript

I am doing node.js server setup from https://scotch.io/tutorials/authenticate-a-node-js-api-with-json-web-tokens. I am new in node.js. I am installing npm install nodemon --save. But when I am run the server with this nodemon server.js.
In the terminal showing:
nodemon is not recognized as internal or external command, operable
program or batch file
node server.js command is working and started the server, But nodemon command is not working.
I am set up the node js server from https://scotch.io/tutorials/authenticate-a-node-js-api-with-json-web-tokens video.
I don't know why it is not working I have tried some command for the install nodemon.
npm install -g nodemon
npm install -g nodemon --save
npm install --save-dev nodemon
npm install -g nodemon#debug
npm install -g --force nodemon
I have seen one link I can´t install nodemon globally, "nodemon" not recognized, But I don't know how to set the path because of my project location in D drive.
I want to run nodemon server.js. How can this be done?

You need to install it globally
npm install -g nodemon
# or if using yarn
yarn global add nodemon
And then it will be available on the path (I see now that you have tried this and it didn't work, your path may be messed up)
If you want to use the locally installed version, rather than installing globally then you can create a script in your package.json
"scripts": {
"serve": "nodemon server.js"
},
and then use
npm run serve
optionally if using yarn
# without adding serve in package.json
yarn run nodemon server.js
# with serve script in package.json
yarn run serve
npm will then look in your local node_modules folder before looking for the command in your global modules

Install nodemon globally:
C:\>npm install -g nodemon
Get prefix:
C:\>npm config get prefix
You will get output like following in your console:
C:\Users\Family\.node_modules_global
Copy it.
Set Path.
Go to Advance System Settings → Environment Variable → Click New (Under User Variables) → Pop up form will be displayed → Pass the following values:
variable name = path,
variable value = Copy output from your console
Now Run Nodemon:
C:\>nodemon .

No need to install nodemon globally. Just run this npx nodemon <scriptname.js>. That's it.

First, write npm install --save nodemon
then in package.json write the followings
"scripts": {
"server": "nodemon server.js"
},
then write
npm run server

I was facing the same issue. I had installed nodemon as a dev-dependency and when I tried to start the server it gave the message that
nodemon is not recognized as internal or external command, operable
program or batch file
Then I installed it globally and tried to start the server and it worked!
npm install -g nodemon

To use nodemon you must install it globally.
For Windows
npm i -g nodemon
For Mac
sudo npm i -g nodemon
If you don't want to install it globally you can install it locally in your project folder by running command npm i nodemon . It will give error something like this if run locally:
nodemon : The term 'nodemon' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling
of the name, or if a path was included, verify that the path is
correct and try again.
To remove this error open package.json file and add
"scripts": {
"server": "nodemon server.js"
},
and after that just run command
npm run server
and your nodemon will start working properly.

This may come to late, But better to say somthing :)
If you don't want to install nodemon globbaly you can use npx, it installs the package at run-time and will behave as global package (keep in mind that it's just available at the moment and does not exist globally!).
So all you need is npx nodemon server.js.
npx can be used out of the box from npm#5.2.0 version and up.

I had the same error a few minutes ago and this is how I've solved it:
1. Install "nodemon" Globally
npm install nodemon -g
2. Then you need to add the npm path to the environment variables
To find the path do this in the terminal:
npm config get prefix
You'll get the output that looks like this: C:\Users\user\AppData\Roaming\npm
If you're not sure about how you can update environment variables on Windows, check this out: Here
3. Run the app again with "nodemon"
Before you run the app, create a new terminal to make sure that the terminal recognises the changes in the environment variables.
Then run:
ex:
nodemon server.js

Does it need to be installed globally? Do you need to be able to just run nodemon server.js ? If not, you could always just call it from your local project directory. Should be here:
node_modules/.bin/nodemon

This line solved my problem in CMD:
npm install --save-dev nodemon

I tried installing the nodemon globally but that doesn't worked for me.
whenever i try to run it always shows me the error:
nodemon : The term 'nodemon' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling
of the name, or if a path was included, verify that the path is
correct and try again.
2. I have found two solutions for this
solution 1:
What i have tried is to update the "scripts" in package.json file and there i have added
"server": "nodemon app.js"
above line of code and after that
npm run server
Soluton 2:
Press the Windows key.
Type "Path" in the search box and select "Edit the system environment variables"
Click on "Environment Variables" near the bottom.
In the "System Variables" section double click on the "Path" variable.
Click "New" on the right-hand side.
Copy and paste this into the box (replace [Username]):
C:\Users[Username]\AppData\Roaming\npm
restart your terminal and VSCode.
Then type nodemon app.js to run the nodemon
i applied solution 2 as we just need to run nodemon [filename.js]

I have fixed in this way
uninstall existing local nodemon
npm uninstall nodemon
install it again globally.
npm i -g nodemon

It is better to install nodemon globally instead as dev dependency to the project.
npm install -g nodemon
Official NPM CDN: Link
This package is used to monitor changes in the javascript files and re run the npm start so that it is easy to dev purposes.

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.
try this link and follow it.fixing npm permissions
https://docs.npmjs.com/getting-started/fixing-npm-permissions#option-2-change-npms-default-directory-to-another-directory

You can run your node app by simply typing nodemon
It First run index.js
You can put your entry point in that file easily.
If you have not installed nodemon then you first you have to install it by
npm install -g nodemon
If you got any permission error then use
sudo npm install -g nodemon
You can check nodemon exists or not by
nodemon -v

For me setting the path variables was enough for the solution:
Step 1) Install nodemon globally using npm install -g nodemon
Step 2) Set the ENVIRONMENT VARIABLES, by adding npm path the PATH variable
1) Open Control Panel, search for environment variable
2) Click open the environment variable
3) Create new variable NPM set it with the path of npm as appears from the nodemon installation cmd output (as seen from nodemon installation screenshot):
4) Now add NPM variable to the PATH variables:
Step 3) Close the 'cmd' and open a fresh one and type nodemon --version
Now we have the nodemon ready to use :)

This issue is also possible if running scripts is disabled on the system. In order to enable it:
Open Windows PowerShell with Run as Administrator
Execute:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
npm install -g nodemon
nodemon app

Just had the same problem after creating a new user profile on my development machine.
The problem was that I wasn't running the console (command prompt\powershell ISE) as admin.
Running as admin solved this problem for me.

Just install Globally
npm install -g nodemon
It worked for me on Windows 10.
nodemon app.js

The Set-ExecutionPolicy cmdlet's default execution policy is Restricted for Windows.
You can try installing nodemon by setting this policy to Unrestricted.
execute command : Set-ExecutionPolicy Unrestricted
and then try installing nodemon and execute command: nodemon -v

First you need to install nodemon globally by using this command:
"npm i -g nodemon" (for Windows) and "sudo npm i -g nodemon" (for Mac)
then run
"nodemon app.js"
Now you will be fine.

Run this command:
npm install nodemon -g
Now it will install the nodemon but the problem with my case is that it is installing nodemon somewhere else.I added Nodejs path from (ProgramFiles(x86)) but that did not worked so i found another solution.
Run above command
There will be a path shown during installation where nodemon is installed,then
[Kindly go to below link to see the path][1]
[1]: https://i.stack.imgur.com/ld2sU.png
Copy the path upto npm and set it to environment variable
Now try the below command,hopefully it will run
nodemon YourAppName.js

All above options are failed, I got the permanent solution for this.
Add below line in package.json under dependencies and run npm install. This will add nodemon package to node_modules and there you go, enjoy the coding.
"nodemon": "^1.17.*"

Try in your packge.json:
put "./node_modules/.bin/nodemon" instead of just "nodemon".
For me it works.

This help me with the same problem to start both nodemon and graphql servers
npm run dev

Step 1: $ npm install nodemon --> install nodemon on your project
Step 2: Add serve in script on package.json file as:
"scripts": {
"serve": "nodemon app.js" // you can change file name accordingly
}
Step 3: $ npm run serve

The following worked for me on windows 11.
Type npm install in the terminal. (Within the same directory as the project)
Then type npm run serve to run the application from the default browser.

Remove nodemon because it's a dev dependency and use node instead of it.
"scripts": {
"start": "node server.js"
},
This worked for me.

Related

can not run js file with nodemon

I install nodemon from npm in project but cant run js file with 'nodemon run start' and facing this error:
nodemon : The term 'nodemon' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
You need to install nodemon globally using the -g option.
npm install -g nodemon
This will add nodemon to your PATH environment variable so that your terminal knows where the executable file for nodemon is.
Otherwise your terminal doesn't know which executable you're trying to run.
Your second option is to run it through npx.
Use the following:
npx nodemon {filename}
npm will handle locating and running the executable for you. The npx command is installed on your computer by default when you install npm.
You will need to install nodemon if you haven't already
for dev environment run
$ npm install --save-dev
to install nodemon globally run
npm install -g nodemon
to run your app/server use
nodemon app
If the name of your entry file is not app use its name in the command
nodemon {filename}

NODE_ENV' is not recognized as an internal or external command, operable program or batch file

I am learning NODE js and i have a server file that includes NODE_env as port configuration , the code works on a MAC but throws up an error on my windows. How do i solve this?
Have you tried installing it globally or include it in your project's or your library's optional dependencies?
if not, try this:
install globally:
npm install -g win-node-env
Or you may include it in your project's or your library's optional dependencies:
npm install --save-optional win-node-env
refer below link for more information
npmjs win-node-env
If you run into this problem in 2021, install cross-env as a dev dependency by running npm i -D cross-env.
Then, modify your command in the package.json file thus:
cross-env NODE_ENV=development node my_script.js
Are you asking how to set NODE_ENV in windows? You can set it as a user or machine environment variable. You can also set it when you call the script in the command line:
NODE_ENV=development node my_script.js

'react-scripts' is not recognized as an internal or external command

I've got a maven project, within which is JavaScript project cloned as a git sub-module. So the directory structure looks like mavenapp/src/main/javascript/[npm project files]
Inside my package.json, the test looks like this:
"test": "react-scripts test --env=jsdom",
but when I try to run npm test, it says
'react-scripts' is not recognized as an internal or external command,
Interestingly, when I clone the javascript project independently I don't get this error. I've tried re-running npm install.
NPM version: 5.5.1
Node.js version: 9.3.0
It is an error about react-scripts file missing in your node_modules/ directory at the time of installation.
Check your react-script dependency is avaliable or not in package.json.
If not available then add it manually via:
npm install react-scripts --save
If react-scripts is present in package.json, then just type this command
npm install
If react-scripts is not present in package.json, then you probably haven't installed it. To do that, run:
npm install react-scripts --save
Try:
rm -rf node_modules && npm install
Wiping node_modules first, often tends to fix a lot of weird, package related issues like that in Node.
Running these commands worked for me:
npm cache clean --force
npm rebuild
npm install
In my situation, some problems happened with my node package. So I run npm audit fix and it fixed all problems
2023 answer: simply remove node_modules folder and run
npm install
or:
yarn
(depends on you're using npm or yarn)
it worked for me!
no need to do more!!!
It waste a lot of my time until I discover this, I got headache...
Faced the same problem, although I am using yarn.
The following worked for me:
yarn install
yarn start
To avoid this issue to re-occur or you face this issue whenever anyone downloads your project fresh.
It's better to add this in dev dependencies using this command:
npm install react-scripts --save-dev
It will get added like this.
"devDependencies": {
"react-scripts": "^4.0.3"
}
Do Commit and push your code.
Running the npm update command solved my problem.
To rectify this issue follow the following steps
run npm install
then run npm start
This worked fine for me
For Portable apps change
package.json
as follows
"scripts": {
"start": "node node_modules/react-scripts/bin/react-scripts start",
"build": "node node_modules/react-scripts/bin/react-scripts build",
"test": "node node_modules/react-scripts/bin/react-scripts test",
"eject": "node node_modules/react-scripts/bin/react-scripts eject"
}
react-scripts should be listed as a dependency when you run npx create-react-app your-app, but for some reason, it gets this error. I will list some steps that I followed that may help you fix this error:
First, check at your React package.json if there is react-scripts or not:
for example, you should see:
"dependencies": {
...
"react-scripts": "4.0.3",
...
},
If it's already there, now try to re-install your dependencies with npm i
If you still get the same error, try to remove your node_modules with rm -rf node_modules/, then re-install your dependencies with npm i
BUT if the package react-scripts wasn't in your package.json file, you should install it by your package manager like:
npm i react-scripts
then try to start your app with npm start
This is how I fix it
Check and Update the path variable (See below on how to update the path variable)
Delete node_modules and package-lock.json
run npm install
run npm run start
if this didn't work, try to install the nodejs and run repair
or clean npm cache npm cache clean --force
To update the path variable
press windows key
Search for Edit the system environmental variable
Click on Environment Variables...
on System variable bottom section ( there will be two section )
Select Path variable name
Click Edit..
Check if there is C:\Program Files\nodejs on the list, if not add this
I uninstalled my Node.js and showed hidden files.
Then, I went to C:\Users\yourpcname\AppData\Roaming\ and deleted the npm and npm-cache folders.
Finally, I installed a new version of Node.js.
I faced the same issue. I solved it using npm audit fix --force
I had the same issue. I did everything which suggested here. but nothing worked. I had installed react-scripts in my node_modules also used cache but all in vain. then I just npx create-react-app and moved all my code into this new folder and all worked.
npx create-react-app myapp
As for me i managed to fix this issue by install this :
npm audit fix --force
and it work after that.
This is not recommended, so plz don't down arrow, but for troubleshooting..
react-scripts is not recognized as an internal or external command is related to npm.
I would update all of my dependencies in my package.json files to the latest versions in both the main directory and client directory if applicable.
You can do this by using an asterisk "*" instead of specifying a specific version number in your package.json files for your dependencies.
For Example:
"dependencies": {
"body-parser": "*",
"express": "*",
"mongoose": "*",
"react": "*",
"react-dom": "*",
"react-final-form": "*",
"react-final-form-listeners": "*",
"react-mapbox-gl": "*",
"react-redux": "*",
"react-responsive-modal": "*",
}
I would then make sure any package-lock.json were deleted and then run npm install and yarn install in both the main directory and the client directory as well if applicable.
You should then be able to run a yarn build and then use yarn start to run the application.
Use git bash or windows cmd with admin rights to run npm install while fixing this issue, running these commands inside the editor's terminals doesn't help.
first run:
npm ci
then:
npm start
In my case, the problem had to do with not having enough file permissions for some files the react-scripts package installation was going to write to. What solved it was running git bash as an administrator and then running npm install --save react-scripts again.
I have tried many of the solutions to this problem found on line, but in my case nothing worked except for reinstalling NVM for Windows (which I am using to manage multiple Node versions). In the installer, it detects installed Node versions and asks the user if they wish for NVM to control them. I said yes and NVM fixed all PATH issues. As a result, things worked as before. This issue may have multiple causes, but corrupted PATH is definitely one of them and (re)installing NVM fixes PATH.
This is rather old question but this might be of some help for future reference. Delete node_modules folder and run npm install again. Worked for me.
In my case , I edited my files on Linux where I had node v14.0.5 installed, when I rebooted to Windows where I had node v14.0.3 I got the same error. So I updated the node version on windows and all went fine for me.
had similar issue.. i used yarn to fix it.
i noticed that react-scripts was not found in my node modules so i decided to download it with npm but i seem to be failing too. so i tried yarn ( yarn add react-scripts) and that solved the nightmare! Hope this work for you as well. Happy debuging folks.
For me, I just re-installed the react-scripts instead of react-scripts --save.
Started getting this error in Azure DevOps yesterday out of nowhere when running npm run build:
'react-scripts' is not recognized as an internal or external command, operable program or batch file.
However when looking at npm ci that completed it was full of errors like:
FetchError: Invalid response body while trying to fetch
https://registry.npmjs.org/#babel%2fcompat-data: ENOENT: no such file
or directory, lstat
'D:\a\1.npm_cacache\content-v2\sha512\58\0b\dc7dce0b33e86d97736b3c419005951e32af28dda3f5b8c746f16d53d4baed1dc2fd2493e9310f744696008400bf8c91ca84f9fb3ebf541ba93a541b144a'
When commenting out the cache everything started working again:
npm_config_cache: $(Pipeline.Workspace)/.npm
- task: Cache#2
inputs:
key: 'npm | "$(Agent.OS)" | $(clientApp)\package-lock.json'
restoreKeys: |
npm | "$(Agent.OS)"
path: $(npm_config_cache)
displayName: Cache npm
The weird thing is that it has worked for over a year up until yesterday (2021-12-02) and we use the exact same code for caching as Microsoft has documented.
https://learn.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#nodejsnpm
Noting Degraded or Unhealthy on Azure DevOps Status
https://status.dev.azure.com/
I had the same problem and I tried the above thing, but that did not work some how. So,
I just typed yarn. And it went.
When I make a new project using React, to install the React modules I have to run "npm install" (PowerShell) from within the new projects ClientApp folder (e.g. "C:\Users\Chris\source\repos\HelloWorld2\HelloWorld2\ClientApp"). The .NET core WebApp with React needs to have the React files installed in the correct location for React commands to work properly.
This worked for me:
Go to the project folder in CLI and type npm install.Go for a similar command if
using yarn etc.
Then type npm start if you are using Npm. Go for a similar command if using yarn
etc.
The file starts working

npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Nuwanst\package.json'

I just want to install socket.io to my project which is located on 3.chat folder. But when I run following command it shows following Warnings.And its not created a node_modules directory inside my project folder. How to fix this?
C:\Users\Nuwanst\Documents\NodeJS\3.chat>npm install socket.io
C:\Users\Nuwanst
`-- socket.io#2.0.3
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Nuwanst\package.json'
npm WARN Nuwanst No description
npm WARN Nuwanst No repository field.
npm WARN Nuwanst No README data
npm WARN Nuwanst No license field.
If you already have package-lock.json file just delete it and try again.
Have you created a package.json file? Maybe run this command first again.
C:\Users\Nuwanst\Documents\NodeJS\3.chat>npm init
It creates a package.json file in your folder.
Then run,
C:\Users\Nuwanst\Documents\NodeJS\3.chat>npm install socket.io --save
The --save ensures your module is saved as a dependency in your package.json file.
Let me know if this works.
Make sure you are on the right directory where you have package.json
You need to make sure that the package.json file exist in the app directory. Run this command where package.json file exists.
For more explanation, I run npm start in c:\selfPractice, but my package.json is in c:\selfPractice\frontend. When I switch to c:\selfPractice, it works.
NOTE: if you are experiencing this issue in your CI pipeline, it is usually because npm runs npm ci instead of npm install. npm ci requires an accurate package-lock.json.
To fix this, whenever you are modifying packages in package.json (e.g. moving packages from devDependencies to Dependencies like I was doing) you should regenerate package-lock.json in your repository by running these commands locally, and then push the changes upstream:
rm -rf node_modules
npm install
git commit package-lock.json
git push
If your folder already have package.json
Then,
Copy the path of package.json
Open terminal
Write:
cd your_path_to_package.json
Press ENTER
Then Write:
npm install
This worked for me
finally, I got a solution if you are getting:-
**npm WARN tar ENOENT: no such file or directory,.......**
then it is no issue of npm or its version it is os permission issue to resolve this you need to use below command:-
sudo chown -R $USER:$USER *
additional
sudo chmod -R 777 *
then run:-
sudo npm i
If you're trying to npm install on a folder that's being rsync'd from somewhere else, remember to add this to your rsync --exclude
yourpath/node_modules
Otherwise, NPM will try to add node_modules and rsync will remove it immediately, causing many npm WARN enoent ENOENT: no such file or directory, open errors.
Delete package.json and package-lock.json file
Then type npm init
after that type npm install socket.io --save
finally type npm install
It works for me
update version in package.json is working for me
I just experienced this error but on looking for the answer online here on stackoverflow I found the answer in the process so I decided to share it also , If this error occurs on a react project you are working on and when you run npm start make sure to change directory into the directory that has react installed in it and it will start working
if your node_modules got installed in say /home/UserName/ like in my case,
your package-lock.json file will also be there. just delete this file, go back to your app folder and run npm init and then npm install <pkgname> (e.g express) and a new node_modules folder will be created for your.
I had this in a new project on Windows. npm install had created a node_modules folder for me, but it had somehow created the folder without giving me full control over it. I gave myself full control over node_modules and node_modules\.staging and it worked after that.
Seems you have installed express in root directory.Copy path of package.json and delete package json file and node_modules folder.
I had the same problem, I resolved by removing all insignificant lines in packages.json e only left "name", "version", "description", "devDependencies", "dependencies", "resolutions". and the error was gone.
the file path you ran is wrong. So if you are working on windows, go to the correct file location with cd and rerun from there.

Gitlab CI Failed: NPM command not found

I have been playing around Gitlabl CI but for some reason I can't get my tests to "passed". It always says npm: command not found
My Gitlab CI config looks like this:
image: node:latest
# This folder is cached between builds
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache:
paths:
- node_modules/
before_script:
- npm install
- npm install eslint -g
- npm install eslint-plugin-react -g
- npm install babel-eslint -g
test:lint:
script:
- eslint src/*
I keep getting the error below and I have No Idea why:
By the way, Im NOT using the gitlab shared runner. Not sure if that contributes to the problem but just to make sure, the machine that has my gitlab runner has all the necessary packages to run nodejs.
Your help is greatly appreciated
Best regards,
The image tag specifies a docker image, hence you must specify the executor of your runner to be docker. Did you perhaps set it to be something else, like shell, when you created the runner?
You can use like below:-
stages:
- build
- deploy
deploy-prod:
image: node:12.13.0-alpine
stage: deploy
script:
- npm i -g firebase-tools
I have same problem.
Gitlab-runner use user of 'gitlab-runner' default when it starts. So the user have not root access.
ps aux|grep gitlab-runner
copy the shell of running
change user:
run /usr/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user root in bash.
gitlab-ci runner test
pass!
kill old pid
nohup /usr/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user root
ps: gitlab-runner -u root also change user.
Your cli is taking ssh executer by default. You probably need docker. Try adding tag in your yml script.
tags: [ <your docker image name> ]
This helped me:
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local
In my case, there are two gitlab-runner. There is no node enviroment in the specific Runner.Then I stopped the wrong one

Categories