Watching for File Changes - Express.js Guide: The Comprehensive Book on Express.js (2014)

Express.js Guide: The Comprehensive Book on Express.js (2014)

Watching for File Changes

This topic is little bit outside of Express.js, but we thought it so important that it’s worth mentioning. Node.js applications are stored in memory, and if we make changes to the source code, we need to restart the process, i.e., node.

There are brilliant tools that can leverage watch method from the core Node.js fs module and restart our servers when we save changes from an editor:

· supervisor (GitHub)

· up (GitHub)

· node-dev (GitHub)

· nodemon (GitHub)

tip

Tip

It’s good to know that Express.js reloads a template file for every new request by default. So, no server restart is necessary. However, we can cache templates by enabling the view cache setting, which we’ll cover at length later in the book.