nodemon does not restart with `--watch src --exec 'yarn run build && yarn start'`

Created on 28 Mar 2017  ยท  7Comments  ยท  Source: remy/nodemon

Why would this not work, what am I doing wrong?

nodemon --watch src --exec 'yarn run build && yarn start'

In src are all my files. It builds and starts just fine, but does not restart when anything is changed. Any ideas?

Most helpful comment

I have the same problem. Doesn't work whether with trailing slah or not.

Nodemon 1.11.0

Explicit file works:

nodemon --watch src/index.ts --exec 'node out/index.js'

Those don't:

nodemon --watch 'src' --exec 'node out/index.js'
nodemon --watch src --exec 'node out/index.js'
nodemon --watch 'src/' --exec 'node out/index.js'
nodemon --watch src/ --exec 'node out/index.js'
nodemon --watch 'src/**/*.ts' --exec 'node out/index.js'

UPDATE FIXED:

Sorry guys, after running nodemon in verbose it told me that by default it only watches *.js files.

After adding -e ts switch it all works again.

nodemon --watch src/ --exec 'node out/index.js' --verbose -e ts

All 7 comments

Nope, no idea.

Can't really give you any better idea without seeing the output or a tree of src.

Sorry, should've given more info.

The tree of src is this:

src/
  pages/
  public/
    css/
    js/
      index.js
  scripts/
  templates/
  404.hbs
  index.hbs

I've tried changing src/index.hbs and src/public/js/index.js but the server does not restart.

The output once I start nodemon the first time is this:

git:master โฏ nodemon --watch src --exec 'yarn run build && yarn start'
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: /path/to/repo/src/**/*
[nodemon] starting `yarn run build && yarn start`
...
<server starts correctly>

I also tried it with: nodemon -L ... and nodemon -e js,hbs ... and nodemon --watch src/**/*.hbs and still no luck.

Should be src/ with a trailing slash.

I have the same problem. Doesn't work whether with trailing slah or not.

Nodemon 1.11.0

Explicit file works:

nodemon --watch src/index.ts --exec 'node out/index.js'

Those don't:

nodemon --watch 'src' --exec 'node out/index.js'
nodemon --watch src --exec 'node out/index.js'
nodemon --watch 'src/' --exec 'node out/index.js'
nodemon --watch src/ --exec 'node out/index.js'
nodemon --watch 'src/**/*.ts' --exec 'node out/index.js'

UPDATE FIXED:

Sorry guys, after running nodemon in verbose it told me that by default it only watches *.js files.

After adding -e ts switch it all works again.

nodemon --watch src/ --exec 'node out/index.js' --verbose -e ts

The following is working for me as a very simple backup solution based on @mcwienczek answer:

"watch": "nodemon --watch . --exec backup -e *"

This watches all files and if any are changed runs a Windows batch file called backup.bat that only copies changed files to OneDrive.

This is the only command that worked for me to get npm to run an arbitrary script.

Including other files just for interest.

_backup.bat_

@echo off
xcopy /d /s /y /EXCLUDE:backup-exclude.txt . C:\Users\<user>\OneDrive\code-backup

_backup-exclude.txt_

.git
node_modules

Closing as @philipjmurphy has a workaround for others to use (thank you!).

make sure your writhing your script are correct try this
"scripts": {
"start": "node server.js",
"server": "nodemon server.js"
},

Was this page helpful?
0 / 5 - 0 ratings