I am using the nodemon package, but it is not restarting the server. It is only showing "restarting due to changes". But in youtube videos, I saw that it was showing "server running" status after that.
In my case, that was not showing. It simply shows "restarting due to changes", my work also does not update when I view it in a browser.
I read lots of related stack overflow questions but none of them helped me ... Installing them locally on my project as devdependent.noting also does not work.
I also tried changing the script tags in the package.json file.
While running, I used nodemon, npm start, nodemon app.js, nodemon lib/dev-server.js --delay 1, nodemon -L, and many more, but nothing helped.
=================================================================================
edited question:
i am using vs code. trying to run my javascript code with express framework .
i am using git bash terminal. whatever basic hello world code also cannot run with nodemon.
the steps i have followed:
node -v and npm -v is working on my bash terminal.
i have created a basic hello world express app . using npm init npm install express --save
i am attaching my github repository of this testApp https://github.com/webdevshiv/testApp.git
then the main problem is about nodemon..
installing nodemon: npm install nodemon --save-dev,also nodemon install -g
in script tag : "scripts": { "start": "node app.js" },
code for running nodemon: nodemon app.js
in my terminal while running this i am getting:
(bash: nodemon: command not found)
but node app.js is working....
then using npx nodemon app.js it was showing-----
([nodemon] 2.0.4 [nodemon] to restart at any time, enterrs[nodemon] watching path(s): *.* [nodemon] watching extensions: js,mjs,json [nodemon] startingnode app.js Example app listening at http://localhost:3000 [nodemon] restarting due to changes... [nodemon] restarting due to changes... [nodemon] restarting due to changes... [nodemon] restarting due to changes.)
you can clearly see on first time it was listening to port but on next times when i do any changes it showing restarting. but not restarting..
before when i am posting this this was the case for using nodemon normally but now nodemon is not working ...
i am attaching my system environment variable path: C:\Program Files\MongoDB\Server\4.2\bin;C:\Program Files\Git\cmd; C:\Program Files\nodejs; C:\Program Files\nodejs\node_modules\npm
i am giving link for my vs code screenshots https://imgur.com/e6ViUaF
https://imgur.com/eWOkG0V
Try adding the path of your system 32 ( in my case 'C:\Windows\System32') to environment variables.
It worked for me
$npm ls chokidar
run the above command in the directory you have nodemon installed.
This worked for me.
The advice from #Adeel is completely correct. This is how I tested the solution:
Clone your demo repository, enter the directory and install dependencies
$ git clone https://github.com/webdevshiv/testApp.git
$ cd testApp
$ npm install
Install nodemon (as described by you and the nodemon website [1])
$ npm install -g nodemon
Use nodemon as described on their website
Just use nodemon instead of node to run your code...
In our case that would be (as #Adeel suggested)
$ nodemon app.js
For me this starts nodemon with the following output:
$ nodemon app.js
[nodemon] 2.0.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node app.js`
Example app listening at http://localhost:3000
When I change anything in app.js now nodemon reloads the express server automatically.
To further improve the setup you could replace the start script in package.json so it looks like this:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon app.js"
},
Now you can just use $ npm start to run nodemon.
[1] https://nodemon.io/
I am trying to automate the server reload using the nodemon. I have it installed locally and have the start set to
nodemon app.js using the code:
"scripts": {
"start": "nodemon app.js"
}
It ran fine for the first time, but after shutting down the system once and reopening my project, it does not seem to run properly anymore. Now it throws an error every time I use the command nodemon app.js.
The error line is:
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.
The best solution I could go about this is:
npm install -D nodemon // install as a dev dependency
npm start // run script start
I am trying to run react-d3-tree-demo following this README.md at https://github.com/bkrem/react-d3-tree-demo
After following the other steps, I got stuck on the second step of trying to run the app locally. The command line returns an error: "'BROWSER' is not recognized as an internal or external command, operable program or batch file," when I try to execute "npm run dev" in the react-d3-tree-demo directory that I cloned from the same repo.
The README.md page instructs to run "npm run dev" in both the react-d3-tree and react-d3-tree-demo directories. I actually got an error when I did that command in the react-d3-tree directory where the command line said the linebreak was incorrect, but I went into the eslintrc.js file and added "'linebreak-style': 0," in the module exports which resolved the error. I've tried turning off my Avast antivirus software which was suggested on another page. Nothing has worked so far.
To reproduce my problem:
Demo:
Clone this repo: git clone https://github.com/bkrem/react-d3-tree-demo.git
cd react-d3-tree-demo
Run yarn or npm install OR run bash ./setup.sh and skip to Running locally
React-D3-Tree library:
Inside the react-d3-tree-demo directory, clone the library: git clone https://github.com/bkrem/react-d3-tree.git
Run yarn or npm install
Running locally:
Set up 2 terminal windows, one in the react-d3-tree-demo directory, the other in react-d3-tree-demo/react-d3-tree (i.e. the sub-directory into which we cloned the library itself)
Run yarn dev/npm run dev in each
Any changes made to the demo app or the library should now automatically rebuild the library and reload the app with the fresh build (via nodemon).
I expect the react app to open a page at localhost:8000 that looks like this: https://bkrem.github.io/react-d3-tree-demo/ however, I get a message from the command line that was detailed earlier. I'm not sure why they told me to clone react-d3-tree inside the demo, I'd appreciate any explanation of that also.
Do an npm install of cross-env in your cloned repo:
npm install --save cross-env
Then in your cloned repo, open up package.json and change dev to this:
"dev": "cross-env BROWSER=none yarn clean:lib && webpack --progress --colors --watch --env dev",
Basically adding this to the beginning of the command: cross-env BROWSER=none
BROWSER is an environment variable, and you can use the cross-env package to properly handle it.
Now try running npm run dev again, and it should work.
There are two fixes I found that work perfectly well
Install cross-env (npm package cross-env) npm install cross-env then you change your dev script to
"electron-dev": "concurrently \"cross-env BROWSER=none yarn start\" \"wait-on http://localhost:3000 && electron .\"",
Install concurrently and run this (on windows though)
"electron-dev": "concurrently \"SET BROWSER=none&&npm run start\" \"wait-on http://localhost:3000 && electron .\""
please note that you also have to install concurrently if not already installed
i success using cross-env, so try this one:
"dev": "concurrently -k "cross-env BROWSER=none npm start" "npm:electron"",
"electron": "wait-on http://localhost:3000 && electron ."
Try this: paste this BROWSER=none in your project's .env file then save and re-run the project. Because maybe this a path related issue.
I'm completely new to deploying front-end code and thus the question.
I have a React App which I need to run as a background process, however I'm a little confused about the how to do this.
I run a npm script
npm run build
to build, minify and serve the project on a server.
The relevant code for the build process is this.
"prebuild": "npm-run-all clean-dist test lint build:html",
"build": "babel-node tools/build.js",
"postbuild": "babel-node tools/distServer.js"
This is the code inside the distServer.js
import express from 'express';
import path from 'path';
import open from 'open';
import compression from 'compression';
const port = 3000;
const app = express();
app.use(compression());
app.use(express.static('dist'));
app.get('*', function(req, res){
res.sendFile(path.join(__dirname, '../dist/index.html'));
});
app.listen(port, function(err){
if(err){
console.log(err);
}else{
open(`http://localhost:${port}`);
}
});
This works and the project runs, however the moment I close my terminal the project stops.
The build process creates, three files,
index.html
index.js
styles.css
Now if I navigate to the index.html and open it in a browser, but naturally, nothing shows up. So I'm assuming that I'd have to run it as a node process. How do I do this on the production server and run it as a background process so that even if I exit the terminal the app continues to run.
I have checked this issue,
How to make a node.js application run permanently?
But this has a javascript file as the entry point, in my case it's a html file. I'm not sure how can I modify my scripts to run the front-end app permanently as a background process. Any help appreciated.
Your Javascript file (distServer.js) is your entry point – it's the file that you run to start your server. Your HTML file (index.html) is only served as a response to the requests.
babel-node is OK for development, but it's not suitable for production. You can precompile your Javascript files to vanilla Javascript, then use forever or pm2 as described in the question you already linked to in order to keep the server running even after you close your terminal.
How you organize your source files and compiled files is up to you, but here's one way to do it (quote from the documentation for an example Node server with Babel):
Getting ready for production use
So we've cheated a little bit by using babel-node. While this is
great for getting something going. It's not a good idea to use it in
production.
We should be precompiling your files, so let's do that now.
First let's move our server index.js file to lib/index.js.
$ mv index.js lib/index.js
And update our npm start script to reflect the location change.
"scripts": {
- "start": "nodemon index.js --exec babel-node --presets es2015,stage-2"
+ "start": "nodemon lib/index.js --exec babel-node --presets es2015,stage-2"
}
Next let's add two new tasks npm run build and npm run serve.
"scripts": {
"start": "nodemon lib/index.js --exec babel-node --presets es2015,stage-2",
+ "build": "babel lib -d dist --presets es2015,stage-2",
+ "serve": "node dist/index.js"
}
Now we can use npm run build for precompiling our assets, and npm run serve for starting our server in production.
$ npm run build
$ npm run serve
This means we can quickly restart our server without waiting for
babel to recompile our files.
Oh let's not forget to add dist to our .gitignore file.
$ touch .gitignore
dist
This will make sure we don't accidentally commit our built files to
git.
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.