*
*
*
*

Installation

Either through cloning with git or by using npm (the recommended way):


And nodetháng will be installed globally lớn your system path.

Bạn đang xem: Nodemon la gi

You can also install nodemon as a development dependency:


For CLI options, use the -h (or --help) argument:


Using nodetháng is simple, if my application accepted a host and port as the arguments, I would start it as so:


Any output from this script is prefixed with , otherwise all output from your application, errors included, will be echoed out as expected.

If no script is given, nodetháng will test for a package.json tệp tin và if found, will run the file associated with the main property (ref).

You can also pass the inspect flag lớn node through the commvà line as you would normally:


nodetháng --inspect ./VPS.js 80

If you have sầu a package.json tệp tin for your app, you can omit the main script entirely & nodemon will read the package.json for the main property và use that value as the phầm mềm.

nodemon will also tìm kiếm for the scripts.start property in package.json (as of nodetháng 1.1.x).

Also kiểm tra out the FAQ or issues for nodetháng.

Automatic re-running

nodetháng was originally written to restart hanging processes such as website servers, but now supports apps that cleanly exit. If your script exits cleanly, nodemon will continue to monitor the directory (or directories) và restart the script if there are any changes.

Manual restarting

Whilst nodemon is running, if you need to manually restart your application, instead of stopping và restart nodetháng, you can type rs with a carriage return, and nodetháng will restart your process.

Config files

nodemon supports local và global configuration files. These are usually named nodemon.json and can be located in the current working directory or in your home directory. An alternative local configuration file can be specified with the --config option.

The specifithành phố is as follows, so that a command line argument will always override the config file settings:

comm& line arguments local config global config

A config tệp tin can take any of the comm& line arguments as JSON key values, for example:


} --run" } }

The above nodetháng.json tệp tin might be my global config so that I have sầu support for ruby files and processing files, and I can run nodetháng chạy thử.pde và nodetháng will automatically know how khổng lồ run the script even though out of the box support for processing scripts.

A further example of options can be seen in sample-nodemon.md

package.json

If you want lớn keep all your package configurations in one place, nodetháng supports using package.json for configuration. Specify the config in the same format as you would for a config tệp tin but under nodemonConfig in the package.json tệp tin, for example, take the following package.json:


}

cảnh báo that if you specify a --config tệp tin or provide a local nodetháng.json any package.json config is ignored.

This section needs better documentation, but for now you can also see nodetháng --help config (also here).

Using nodetháng as a module

Please see doc/requireable.md

Using nodetháng as child process

Please see doc/events.md

Running non-node scripts

nodetháng can also be used khổng lồ exeđáng yêu & monitor other programs. nodemon will read the file extension of the script being run và monitor that extension instead of .js if there"s no nodemon.json:


nodemon --exec " pykhông lớn -v" ./ứng dụng.py

Now nodemon will run phầm mềm.py with pykhông lớn in verbose mode (note that if you"re not passing args to the exec program, you don"t need the quotes), and look for new or modified files with the .py extension.

Default executables

Using the nodemon.json config file, you can define your own default executables using the execMap property. This is particularly useful if you"re working with a language that isn"t supported by mặc định by nodemon.

To add tư vấn for nodetháng to know about the .pl extension (for Perl), the nodemon.json file would add:


}

Now running the following, nodemon will know to use perl as the executable:


nodemon script.pl

It"s generally recommended lớn use the global nodetháng.json lớn add your own execMap options. However, if there"s a common mặc định that"s missing, this can be merged in lớn the project so that nodemon supports it by mặc định, by changing mặc định.js and sending a pull request.

Monitoring multiple directories

By default nodetháng monitors the current working directory. If you want khổng lồ take control of that option, use the --watch option khổng lồ add specific paths:


nodetháng --watch app --watch libs app/hệ thống.js

Now nodetháng will only restart if there are changes in the ./phầm mềm or ./libs directory. By mặc định nodetháng will traverse sub-directories, so there"s no need in explicitly including sub-directories.

Xem thêm: Năm Nay Là Năm Gì, 2021 Là Năm Con Gì ? Có Tốt Không Năm 2021 Mệnh Gì

Don"t use unix globbing khổng lồ pass multiple directories, e.g --watch ./lib/*, it won"t work. You need a --watch flag per directory watched.

Specifying extension watch list

By mặc định, nodetháng looks for files with the .js, .mjs, .coffee, .litcoffee, and .json extensions. If you use the --exec option and monitor ứng dụng.py nodemon will monitor files with the extension of .py. However, you can specify your own menu with the -e (or --ext) switch lượt thích so:


nodetháng -e js,pug

Now nodetháng will restart on any changes lớn files in the directory (or subdirectories) with the extensions .js, .pug.

Ignoring files

By mặc định, nodemon will only restart when a .js JavaScript file changes. In some cases you will want lớn ignore some specific files, directories or tệp tin patterns, lớn prsự kiện nodetháng from prematurely restarting your application.

This can be done via the command line:


nodemon --ignore lib/ --ignore tests/

Or specific files can be ignored:


nodemon --ignore lib/ứng dụng.js

Patterns can also be ignored (but be sure to quote the arguments):


nodemon --ignore " lib/*.js"

lưu ý that by mặc định, nodetháng will ignore the .git, node_modules, bower_components, .nyc_output, coverage & .sass-cabịt directories và add your ignored patterns khổng lồ the menu. If you want to indeed watch a directory like node_modules, you need to override the underlying default ignore rules.

Application isn"t restarting

In some networked environments (such as a container running nodemon reading across a mounted drive), you will need to use the legacyWatch: true which enables Chokidar"s polling.

Via the CLI, use either --legacy-watch or -L for short:


nodetháng -L

Though this should be a last resort as it will poll every tệp tin it can find.

Delaying restarting

In some situations, you may want to lớn wait until a number of files have changed. The timeout before checking for new file changes is 1 second. If you"re uploading a number of files & it"s taking some number of seconds, this could cause your tiện ích lớn restart multiple times unnecessarily.

To add an extra throttle, or delay restarting, use the --delay command:


nodemon --delay 10 hệ thống.js

For more precision, milliseconds can be specified. Either as a float:


nodetháng --delay 2.5 hệ thống.js

Or using the time specifier (ms):


nodetháng --delay 2500ms VPS.js

The delay figure is number of seconds (or milliseconds, if specified) to lớn delay before restarting. So nodetháng will only restart your phầm mềm the given number of seconds after the last file change.

If you are setting this value in nodetháng.json, the value will always be interpreted in milliseconds. E.g., the following are equivalent:


nodetháng --delay 2.5

Gracefully reloading down your script

It is possible to lớn have nodetháng skết thúc any signal that you specify to lớn your application.


nodemon --signal SIGHUPhường server.js

Your application can handle the signal as follows.


process . once ( "SIGHUP" , function ( ) )

Please note that nodetháng will sover this signal lớn every process in the process tree.

If you are using cluster, then each workers (as well as the master) will receive sầu the signal. If you wish khổng lồ terminate all workers on receiving a SIGHUP, a common pattern is lớn catch the SIGHUPhường in the master, and forward SIGTERM khổng lồ all workers, while ensuring that all workers ignore SIGHUPhường.


if ( cluster . isMaster ) } ) ; } else ) }

Controlling shutdown of your script

nodemon sends a kill signal lớn your application when it sees a tệp tin update. If you need to clean up on shutdown inside your script you can capture the kill signal & handle it yourself.

The following example will listen once for the SIGUSR2 signal (used by nodemon lớn restart), run the clean up process và then kill itself for nodetháng lớn continue control:


process . once ( "SIGUSR2" , function ( ) ) ; } ) ;

chú ý that the process.kill is only called once your shutdown jobs are complete. Hat tip to lớn Benjie Gillam for writing this technique up.

Triggering events when nodetháng state changes

If you want growl lượt thích notifications when nodetháng restarts or khổng lồ trigger an action when an sự kiện happens, then you can either require nodemon or add sự kiện actions khổng lồ your nodemon.json tệp tin.

Xem thêm: Drastic Là Gì - Drastic In Vietnamese

For example, lớn trigger a notification on a Mac when nodetháng restarts, nodetháng.json looks lượt thích this:


}

A full danh sách of available events is listed on the event states wiki. Note that you can bind to lớn both states và messages.

Pipe output to somewhere else




Chuyên mục: Blog