Nodemon not reloading on volume

I’m using nodemon on my physical OSX host to rerun tests when files change.

This is not working for me, and looking at some other threads, it might be due to:

  • The virtual machine docker host (run with docker-machine).
  • nodemon not working with docker.
  • Watching files not working with docker.

I’m having a real hard time to know in what direction to go. The whole idea is to develop in the docker container, so not having watch mode is a dealbreaker here.

How do I go forward? Should I go into the virtual machine instead of using docker-machine? Should I expose a shared directory somehow? Replace nodemon? Replace docker?

Cheers!

Update:
I followed below guide, and remade some code. At first docker-compose up, nodemon magically worked for me. github.com/marcusnielsen/rxjs-server for reference code. Check open branches/PRs, but otherwise I might have merged the setup to master already.

Guide:

To me the original issue sounds like filesystem notifications – they don’t really work with VirtualBox shared folders as far as I’m aware (so e.g. nodemon is listening for FS events on the Linux end, but the native Mac save events don’t get propagated through vboxfs into the Linux VM).

I would be curious to know what you did to get it working? I do think that some projects like nodemon have a poll-based backup when FS events are unavailable, but I don’t know how common it is.

I had the same issue today and i found a very easy way to fix it. I looked up the docs from nodemon (GitHub - remy/nodemon: Monitor for any changes in your node.js application and automatically restart the server - perfect for development) and found that you have to start nodemon with the flag “-L” if you are running it in a container.

Example start command below:

nodemon -L index.js

Information about the -L flag:

In some networked environments (such as a container running nodemon reading across a mounted drive), you will need to use the legacyWatch: true which enables Chokidar’s polling.

And they also saying that it should be a last resort as it will poll every file it can find.