LinuxCommandLibrary

nodemon

Restart Node.js application on file changes

TLDR

Execute the specified file and watch a specific file for changes

$ nodemon [path/to/file.js]
copy

Manually restart nodemon (note nodemon must already be active for this to work)
$ rs
copy

Ignore specific files
$ nodemon --ignore [path/to/file_or_directory]
copy

Pass arguments to the node application
$ nodemon [path/to/file.js] [arguments]
copy

Pass arguments to node itself if they're not nodemon arguments already (e.g. --inspect)
$ nodemon [arguments] [path/to/file.js]
copy

Run an arbitrary non-node script
$ nodemon --exec "[command_to_run_script] [options]" [path/to/script]
copy

Run a Python script
$ nodemon --exec "python [options]" [path/to/file.py]
copy

SYNOPSIS

nodemon [options] [script.js] [arguments]

PARAMETERS

script.js
    The Node.js script to execute. If omitted, nodemon will try to use the main property in package.json or index.js

arguments
    Arguments passed to the script.js when it's executed.

-v, --version
    Show version number.

-h, --help
    Show help information.

-c, --config <path>
    Specify a custom nodemon.json configuration file.

-w, --watch <glob|file|dir>
    A file, glob, or directory to watch for changes. Multiple paths can be specified.

-i, --ignore <glob|file|dir>
    A file, glob, or directory to ignore. Multiple paths can be specified.

-x, --exec <command>
    The command to execute instead of `node`. E.g., `--exec python`.

-e, --ext <extensions>
    File extensions to watch (default: js,mjs,cjs,json).

-V, --verbose
    Show all system details on startup.

-q, --quiet
    Suppress all output except error messages.

--delay <time>
    Delay restart in milliseconds (default: 1000ms).

--exitcrash
    Exit immediately if the script crashes.

--legacy-watch
    Use legacy watch for file system changes.

DESCRIPTION

Nodemon is a command-line utility that automatically restarts your Node.js application whenever it detects changes in the file system. This eliminates the need to manually restart the server after each code modification, significantly improving developer productivity. It's particularly useful during development and testing. Nodemon monitors the directory containing your script and restarts the process if any file within that directory changes. It also supports configuration files to customize the monitored files, ignored directories, and restart behavior. It's easily installed via npm and can be used as a simple drop-in replacement for the `node` command when starting your application.

CONFIGURATION FILES

Nodemon supports configuration via a nodemon.json file. This file allows you to specify which files to watch, which files to ignore, and other settings. It can simplify command-line arguments.

SIGNALS

When nodemon restarts your script, it sends a SIGTERM signal to the previous process. This allows your application to gracefully shut down before the new process starts.

SEE ALSO

node(1), npm(1)

Copied to clipboard