How can I execute the start script from a package.json file with Nodemon?
-
You sure you can execute a start script from package.json? Because from what I know package.json is to list all your dependencies and nodemon is to keep your process running. I am not quite sure what you are hinting at here? – Saras Arya Nov 23 '15 at 20:23
25 Answers
This will be a simple command for this
nodemon --exec npm start

- 30,738
- 21
- 105
- 131

- 15,451
- 11
- 52
- 85
-
What if I need to run only tests without running the app? You solution runs both. – Serg Oct 04 '18 at 10:32
-
2this does run `npm start` but does not start the node server for me.. how would it know where server.js is ? – Sonic Soul Apr 26 '19 at 15:51
-
1This is the correct answer to the question. It is up to the user to make sure their NPM scripts actually do what they want them to. You can use nodemon directly in your scripts, but that's not what was asked. This is the proper way to have nodemon rerun scripts on changes. – Jon Church Jul 07 '21 at 19:08
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

- 11,193
- 6
- 29
- 32
-
2Sorry, looking for a way to execute the start script _with_ nodemon, not execute nodemon in the start script. Sorry if that wasn't clear. – Citronen Nov 24 '15 at 15:01
-
8
-
6
-
3I'm a beginner with npm. I don't understand why do we need to specify the start script while we can use nodemon out of the box? I just install nodemon with npm and use it directly without specifying any script and it works perfectly. – Hokhy Tann Apr 25 '18 at 09:29
-
2
-
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.

- 30,738
- 21
- 105
- 131

- 714
- 9
- 10
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

- 30,738
- 21
- 105
- 131

- 1,539
- 17
- 32
Use -exec
:
"your-script-name": "nodemon [options] --exec 'npm start -s'"

- 30,738
- 21
- 105
- 131

- 19,126
- 5
- 52
- 83
-
-
Just `nodemon [options] --exec 'npm start -s'` if you want to do it from the command line. – nathanhleung Nov 23 '15 at 21:03
-
-
-
@liuliang It's a shortcut for `--loglevel silent` (it was just an example). – KeatsPeeks Sep 23 '21 at 09:47
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 regularly:
npm start

- 18,658
- 9
- 54
- 82

- 149
- 1
- 4
First change your package.json file,
"scripts":
{
"start": "node ./bin/www",
"start-dev": "nodemon ./app.js"
},
After that, execute command
npm run start-dev

- 30,738
- 21
- 105
- 131

- 103
- 1
- 8
-
1But when you run off of `app.js` you are bypassing everything that `./bin/www` does... – Jake Wilson Mar 23 '18 at 21:30
-
2
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

- 7,309
- 5
- 27
- 46
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" }

- 59
- 1
- 1
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.

- 30,738
- 21
- 105
- 131

- 2,128
- 1
- 15
- 15
I simply use 'npx' in the terminal to set up nodemon and execute it
npx nodemon

- 73
- 1
- 8
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.

- 33,893
- 13
- 69
- 83

- 567
- 1
- 6
- 20
-
not true, for this to work, only add nodemon with dev dependencies will do, just that "nodemon" won't be available at your command line if you run it directly. – jimzcc Aug 19 '22 at 04:55
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).

- 729
- 9
- 11
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"
}

- 30,738
- 21
- 105
- 131

- 8,987
- 4
- 35
- 35
{ "name": "backend", "version": "0.0.0", "private": true, "scripts": { "start": "nodemon ./bin/www" }, "dependencies": { "bcrypt": "^5.0.1", "cookie-parser": "~1.4.4", "debug": "~2.6.9", "express": "~4.16.1", "hbs": "^4.1.2", "http-errors": "~1.6.3", "morgan": "~1.9.1", "nodemon": "^2.0.12" } }
use "nodemon ./bin/www" scripts > start
- eg:
"scripts": { "start": "nodemon ./bin/www" },

- 27
- 9
Try this, with watch:
nodemon --exec ts-node pathtoapp/filewithserver.ts -e ts
my project example: nodemon --exec ts-node src/server.ts -e ts

- 171
- 1
- 4
First install package for nodemon
as dev dependencies using
$ npm i nodemon -D
Then your package.json
will have:
"devDependencies": {
"nodemon": "^2.0.20"
}
Then you can edit change package.json
scripts
part as
"scripts": {
"start": "node app.js",
"dev": "nodemon app.js"
}
Then you can use command:
$ npm run dev

- 59
- 7
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"
},

- 30,738
- 21
- 105
- 131

- 3,778
- 4
- 35
- 63
-
You can still make it "start-dev": "nodemon ./bin/www" if you install it under devDependencies – WoLfPwNeR Apr 01 '19 at 20:07
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).

- 5,226
- 4
- 45
- 50
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

- 766
- 2
- 14
- 28
You can also install nodemon as a development dependency:
npm install --save-dev nodemon
or using yarn: yarn add nodemon -D
.
With a local installation, nodemon will not be available in your system path or you can't use it directly from the command line. 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
.
In other words just run it with npx nodemon index.js
This is the right way
{
"name": "cyber",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon --exec ts-node src/app.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@tensorflow/tfjs": "^4.8.0"
}
}

- 1
- 2
Just use the command : npx nodemon app.js
This is very simple ! and we can run the below command without altering the package.json file in your project