Pm2 ignore watch

When using PM2, the “ignore watch” option allows you to specify specific files or directories to be excluded from being watched for changes. This can be useful when you have large directories or files that you don’t want to be constantly monitored for modifications, which can improve performance and reduce unnecessary reloads.

The syntax for ignoring files or directories is as follows:

pm2 start app.js --ignore-watch="path/to/file1,path/to/directory1"

In this example, the file “path/to/file1” and the directory “path/to/directory1” will be ignored while watching for changes.

You can also use glob patterns to ignore multiple files or directories. For instance, to ignore all JavaScript files in a directory:

pm2 start app.js --ignore-watch="path/to/*.js"

Additionally, you can specify multiple ignore patterns separated by commas:

pm2 start app.js --ignore-watch="path/to/file1,path/to/file2,path/to/file3"

It’s important to note that the paths specified in the “ignore-watch” option are relative to the current working directory.

This option can be helpful in scenarios where you have generated files, log files, or other temporary files that are constantly changing but not relevant to your application’s execution. By excluding them from being watched, you can avoid unnecessary restarts and improve overall performance.

Leave a comment