Modern JavaScript Web Development Cookbook
上QQ阅读APP看书,第一时间看更新

How it works...

The command most interesting for us is the second one. When you run it, nodemon will start monitoring, meaning it will watch whatever directory you selected (out, in this case) and whenever it detects some file change, it will wait one second (to make sure, for example, that all files are saved) and then it will rerun the application. How did I do this?

Initially, I started nodemon. When you do npm run nodemon, the project is built and then run, and nodemon keeps waiting for any changes; see the following screenshot:

 When you start nodemon, it builds the project, runs it, and keeps watching out for any changes that need a restart

Afterwards, I just added a simple console.log() line, so a file would be changed; the following screenshot was the result, showing the rebuilt and restarted code, plus the extra output line:

 After any change in a watched file, nodemon will restart the project. In this case, I had just added a line logging ADDED TEXT JUST FOR THE CHANGE.

That's all there is to it. The application will be rebuilt and restarted automatically, without us having to manually rerun npm start each and every time; a big help!

Read more about nodemon at  http://nodemon.io/ and  https://github.com/remy/nodemon.