matt2mi
matt2mi

Reputation: 154

Nodemon doesn't exec command while restarting

I have a problem about the --exec parameter of nodemon. Following this article (http://blog.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/) i try to set up my dev environnement with only NPM but nodemon refuse to serve my node server when i put --exec argument.

My scripts in package.json :

"scripts": {
    "clean": "rimraf src/app/build/app.bundle.js",
    "build": "browserify src/app/scripts/app.js > src/app/build/app.bundle.js",
    "serve": "nodemon server.js --ignore src/app/build --exec \"npm run build\"",
    "cbs": "npm run clean && npm run build && npm run open && npm run serve",

    "open:dev": "opener http://localhost:9000",
},

And this is what i get in my git bash :

[email protected] serve C:\Users\Mdeumie\Projets\Archi\poc-js-pdf
nodemon server.js --ignore src/app/build --exec "npm run build"

[nodemon] 1.8.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `npm run build server.js`

[email protected] build C:\Users\Mdeumie\Projets\Archi\poc-js-pdf
browserify src/app/scripts/app.js > src/app/build/app.bundle.js "server.js"

[nodemon] clean exit - waiting for changes before restart

Off course my server.js is not reachable in my browser and i don't understand why it seems to be executing this starting npm run build server.js

Thanks if someone has an idea about this.

Upvotes: 3

Views: 3552

Answers (1)

Datsik
Datsik

Reputation: 14824

Try removing the --exec * from your serve script and change it to

"npm run build && nodemon"

Make a file nodemon.json in your root and inside try putting

{
  "ignore": ["src/app/build"],
  "events": {
    "exit": "npm run build"
  }
}

So your nodemon will run and do its thing and then it should trigger the build on restart

List of events: https://github.com/remy/nodemon/blob/master/doc/events.md

Upvotes: 8

Related Questions