I’m developing a module in Node.js which I’ve npm-linked into another projects node_modules folder. I’d like to restart this other projects server upon file changes in my module. Nodemon ignores node_modules by default, but I assumed I could override this using nodemon --watch node_modules/my_module – but can’t get it to work. If I temporarily remove node_modules from Nodemons lib/config/defaults.js it works, which probably confirms that the problem has to do with overriding default behavior.
Asked
Active
Viewed 3,486 times
17
-
Running into this myself. I thought of using forever.js, but it looks like that library doesn't actually support sending log output to stdout (which is a dealbreaker in my opinion). – Jul 30 '15 at 01:58
-
...aaaand I found the solution. I suppose I should have actually tried this before. – Jul 30 '15 at 02:16
1 Answers
11
Using nodemon
1.2.1, I'm able to do the following to get watches working with an npm link:
$ nodemon --watch . --watch $(realpath node_modules/my_module)
Basically...you have to watch the directory you're in (your project directory), and then specify a watch to the symlink itself. nodemon
by default ignores node_modules
, so explicitly specifying the watch fixes this. You may try updating your version of nodemon
if this doesn't work for you.

MiniGod
- 3,683
- 1
- 26
- 27
-
This doesn't appear to work anymore, see [this issue](https://github.com/remy/nodemon/issues/794); – Tamlyn Jun 28 '17 at 14:18
-
@Tamlyn Hey - feel free to edit my answer to include a new fix, if it exists. If it's a good answer, I can make this community wiki and leave it open for edits. – Jun 30 '17 at 05:46
-
1This worked for me just now after I ran `brew install coreutils` (macOS). Otherwise `realpath` command was not found. It's a good idea to run `realpath node_modules/my_module` separately to ensure it returns something meaningful and only then call `nodemon ...`. – Alexander Kachkaev Dec 14 '17 at 17:35
-
1Using this solution I created a small wrapper that will automatically watch all linked modules. Just `npm install -g linkemon`, and then just use the `linkemon` command in place of `nodemon`. – Mario Sep 20 '18 at 15:51