expressjs-utilities
nodemon
live reload code changes
The nodemonConfig section in the package.json file is used to configure the behavior of the Nodemon tool, which is a utility that monitors changes in your Node.js application and automatically restarts the server when changes are detected. Here's an explanation of the different properties in the nodemonConfig object:
//package.json
"nodemonConfig": {
"restartable": "rs",
"ignore": [
"node_modules/**/node_modules"
],
"delay": "2500",
"env": {
"NODE_ENV": "development",
"PORT": 4000
}
},
-
restartable: This property specifies the command that triggers a server restart. In this case,rsis used as the restart command. So, when you make changes to your code and save the files, you can trigger a server restart by typingrsin the terminal where Nodemon is running. -
ignore: This property is an array of patterns specifying files or directories that Nodemon should ignore when monitoring for changes. In the given example, thenode_modulesdirectory is ignored, specifically excluding nestednode_modulesdirectories. This is useful to prevent Nodemon from restarting the server unnecessarily when changes occur in dependencies. -
delay: This property sets the delay (in milliseconds) before Nodemon restarts the server after detecting changes. In this case, the delay is set to 2500 milliseconds (or 2.5 seconds). This delay allows time for any file changes to stabilize before the server restarts. -
env: This property defines the environment variables that will be set when running the application with Nodemon. In the given example, two environment variables are specified:NODE_ENVandPORT.NODE_ENVis set to "development", indicating that the application is running in a development environment.PORTis set to 4000, specifying the port number on which the server should listen.
To use this nodemonConfig in your project, you need to have Nodemon installed as a development dependency. You can install it by running npm install --save-dev nodemon. Once Nodemon is installed, you can start your server by running nodemon in the terminal, and it will automatically restart whenever changes are made to your code.
Please note that the nodemonConfig section in the package.json file is optional. If you don't specify it, Nodemon will use default settings. However, using a nodemonConfig allows you to customize Nodemon's behavior according to your specific requirements.