How to monitor file changes and restart Node program in Vagrant inside?

  node.js, question

This is the first time to write a Node project in the team. Before, PHP environment was managed by Vagrant, so I plan to do the same for this Node project. But there was a problem.

I shared the development directory through NFS. When my file changes, the Node program in Vagrant needs to restart automatically.

I tried to use pm2, configured as follows:

bracket
 "apps": [{
 "name": "ase",
 "script": "index.coffee",
 "watch": true,
 "watch_options": {
 "usePolling": true
 bracket
 }]
 bracket

Although file changes can be monitored, the process takes at least five or six seconds. Compared with the situation that pm2 is not used for one second on this machine, it is too slow … and sometimes it cannot be monitored.

I don’t know how everyone solved this problem. Or, when developing Node projects, how do you ensure the consistency of the development environment and the online environment as much as possible?

I am the subject. I found the solution half a month ago and used it for half a month. I feel good now.

The following are the solutions:

Vagrant added 1 Central Processor and shared 2.

Vagrantfile adds mount options after nfs configuration:

mount_options: ['rw', 'vers=3', 'tcp', 'fsc' ,'actimeo=1']

Add this article to the pm2 configuration file:

"watch_options": {
 "usePolling": true
 bracket