Month End Sale: Get Extra 10% OFF on Job-oriented Training! Offer Ending in
D
H
M
S
Get Now

Nodemon in Node.js

Level : Intermediate
Mentor: Shailendra Chauhan
Duration : 00:02:00

What is a Nodemon?

A nodemon is a utility that automatically restarts your node.js server based on file modifications. It enables easy development of node.js-based applications.

Features of Nodemon

  • Automatic Restart: Nodemon watches the directory's files and restarts the server when any changes are detected.
  • Supports All File Types: Compatible with every file type that Node.js requires or imports.
  • Custom Configuration: Users can configure Nodemon using command line options or a configuration file (nodemon.json).
  • Integration with Express: Works seamlessly with Express.js and other popular frameworks.
  • Flexible Exclusions: You can exclude specific files or folders from monitoring to avoid wasteful restarts.
  • Cross-platform: Works with Windows, macOS, and Linux operating systems.
  • Signal Handling: Handles termination signals (SIGTERM, SIGINT) gracefully, resulting in clean shutdowns.
  • Event Logging: Generates extensive logs of file modifications and server restarts for troubleshooting reasons.

Installation of Nodemon

  • Install globally: npm install -g nodemon.
  • Install as a development dependency: npm install --save-dev nodemon.

Nodemon Usage

  • Start your Node.js application with Nodemon rather than the node command.
  • Rather than node app.js, use nodemon app.js.
  • Nodemon will monitor your files for changes and restart the server automatically if needed.

Configuration

  • Nodemon has several configuration parameters that can be set in a nodemon.json file or via command-line arguments.
  • Configuration options include ignoring certain files or directories, postponing restarts, setting environment variables, and so forth.

Command Line Options of Nodemon

  • --exec <executable>: Run the script using the specified executable, which is node by default.
  • --ext <extensions>: Specify the file extensions to monitor; defaults to js,json.
  • --watch <directory>: Specifies the directory to monitor for changes. By default, nodemon monitors the current directory.
  • --ignore <pattern>: Allows you to specify patterns to ignore files. Separate numerous patterns with commas.
  • --delay <seconds>: Set the delay before restarting the process; default is 1 second.
  • --quiet: Disable nodemon console log messages other than errors.
  • --verbose: Prints additional debug information.
  • --version: Print nodemon's version number and then exit.
  • --help: Show the help information.
  • --config <file>: Define a configuration file.
Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this