Add this to script object from your project's package.json file
"start":"nodemon index.js"
It should be like this
"scripts": { "start":"nodemon index.js" }
To avoid a global install, add Nodemon as a dependency, then...
package.json
"scripts": {
"start": "node ./bin/www",
"start-dev": "./node_modules/nodemon/bin/nodemon.js ./bin/www"
},
If you have nodemon
installed globally, simply running nodemon
in your project will automatically run the start
script from package.json
.
For example:
"scripts": {
"start": "node src/server.js"
},
From the nodemon documentation:
nodemon will also search for the scripts.start property in package.json (as of nodemon 1.1.x).
Use -exec
:
"your-script-name": "nodemon [options] --exec 'npm start -s'"
If globally installed then
"scripts": {
"start": "nodemon FileName.js(server.js)",
},
Make sure you have installed nodemon
globally:
npm install -g nodemon
Finally, if you are a Windows user, make sure that the security restriction of the Windows PowerShell is enabled.
In package json
:
"scripts": {
"start": "node index",
"dev": "nodemon index"
},
"devDependencies": {
"nodemon": "^2.0.2"
}
And in the terminal for developing:
npm run dev
And for starting the server regular:
npm start
This will be a simple command for this
nodemon --exec npm start
In package.json file. change file like this
"scripts":{
"start": "node ./bin/www",
"start-dev": "nodemon ./app.js"
},
and then execute npm run start-dev
You can also install nodemon globally for frequent use:
npm i nodemon -g
or sudo npm i nodemon -g
then edit your package.json:
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
},
Generally, 'dev' specifies developmental use (npm run dev).
It will depend on types of your Nodemon installation. If you install Nodemon globally by using commands (npm install nodemon --global
or npm install nodemon -g
), you do not have to specify any script for Nodemon in your package.json file. Just executing command nodemon index.js
will run your project.
But if you install Nodemon locally by command npm install nodemon
then you have to specify the script. If you name it as start then npm run start
or npm start
will trigger the server to run.
// Absolutely no need for global installation
"scripts": {
"start": "nodemon index.js"
}
I use Nodemon version 1.88.3 in my Node.js project. To install Nodemon, see in https://www.npmjs.com/package/nodemon.
Check your package.json, see if "scripts" has changed like this:
"scripts": {
"dev": "nodemon server.js"
},
server.js
is my file name, you can use another name for this file like app.js
.
After that, run this on your terminal: npm run dev
In package json:
{
"name": "abc",
"version": "0.0.1",
"description": "my server",
"scripts": {
"start": "nodemon my_file.js"
},
"devDependencies": {
"nodemon": "~1.3.8",
},
"dependencies": {
}
}
Then from the terminal you can use npm start
Nodemon installation: https://www.npmjs.com/package/nodemon
First change your package.json file,
"scripts":
{
"start": "node ./bin/www",
"start-dev": "nodemon ./app.js"
},
After that, execute command
npm run start-dev
Nodemon emits events upon every change in state; start, restart crash, etc. You can add a Nodemon configuration file (nodemon.json) like so:
{
"events": {
"start": "npm run *your_file*"
}
}
Read more in Nodemon events — run tasks at server start, restart, crash, exit.
I know it's 5 years late, if you want to use nodemon.json
you may try this,
{
"verbose": true,
"ignore": ["*.test.js", "fixtures/*"],
"execMap": {
"js": "electron ." // 'js' is for the extension, and 'electron .' is command that I want to execute
}
}
The execMap
will execute like a script
in package.json, then you can run nodemon js
I have a TypeScript file called "server.ts", The following npm scripts configures Nodemon and npm to start my app and monitor for any changes on TypeScript files:
"start": "nodemon -e ts --exec \"npm run myapp\"",
"myapp": "tsc -p . && node server.js",
I already have Nodemon on dependencies. When I run npm start
, it will ask Nodemon to monitor its files using the -e
switch and then it calls the myapp
npm script which is a simple combination of transpiling the typescript files and then starting the resulting server.js. When I change the TypeScript file, because of -e
switch the same cycle happens and new .js files will be generated and executed.
Source: Stackoverflow.com