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.
How do I monitor symlinked modules with Nodemon?
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). –
Assortment
...aaaand I found the solution. I suppose I should have actually tried this before. –
Assortment
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.
This doesn't appear to work anymore, see this issue; –
Selfsame
@Selfsame 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. –
Assortment
This 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 ...
. –
Norven Using 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
. –
Kief © 2022 - 2024 — McMap. All rights reserved.