You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 18KB

4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
4 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <p align="center">
  2. <img src="https://user-images.githubusercontent.com/13700/35731649-652807e8-080e-11e8-88fd-1b2f6d553b2d.png" alt="Nodemon Logo">
  3. </p>
  4. # nodemon
  5. nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected.
  6. nodemon does **not** require *any* additional changes to your code or method of development. nodemon is a replacement wrapper for `node`. To use `nodemon`, replace the word `node` on the command line when executing your script.
  7. [![NPM version](https://badge.fury.io/js/nodemon.svg)](https://npmjs.org/package/nodemon)
  8. [![Travis Status](https://travis-ci.org/remy/nodemon.svg?branch=master)](https://travis-ci.org/remy/nodemon) [![Backers on Open Collective](https://opencollective.com/nodemon/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/nodemon/sponsors/badge.svg)](#sponsors)
  9. # Installation
  10. Either through cloning with git or by using [npm](http://npmjs.org) (the recommended way):
  11. ```bash
  12. npm install -g nodemon
  13. ```
  14. And nodemon will be installed globally to your system path.
  15. You can also install nodemon as a development dependency:
  16. ```bash
  17. npm install --save-dev nodemon
  18. ```
  19. With a local installation, nodemon will not be available in your system path. Instead, the local installation of nodemon can be run by calling it from within an npm script (such as `npm start`) or using `npx nodemon`.
  20. # Usage
  21. nodemon wraps your application, so you can pass all the arguments you would normally pass to your app:
  22. ```bash
  23. nodemon [your node app]
  24. ```
  25. For CLI options, use the `-h` (or `--help`) argument:
  26. ```bash
  27. nodemon -h
  28. ```
  29. Using nodemon is simple, if my application accepted a host and port as the arguments, I would start it as so:
  30. ```bash
  31. nodemon ./server.js localhost 8080
  32. ```
  33. Any output from this script is prefixed with `[nodemon]`, otherwise all output from your application, errors included, will be echoed out as expected.
  34. You can also pass the `inspect` flag to node through the command line as you would normally:
  35. ```bash
  36. nodemon --inspect ./server.js 80
  37. ```
  38. If you have a `package.json` file for your app, you can omit the main script entirely and nodemon will read the `package.json` for the `main` property and use that value as the app ([ref](https://github.com/remy/nodemon/issues/14)).
  39. nodemon will also search for the `scripts.start` property in `package.json` (as of nodemon 1.1.x).
  40. Also check out the [FAQ](https://github.com/remy/nodemon/blob/master/faq.md) or [issues](https://github.com/remy/nodemon/issues) for nodemon.
  41. ## Automatic re-running
  42. nodemon was originally written to restart hanging processes such as web servers, but now supports apps that cleanly exit. If your script exits cleanly, nodemon will continue to monitor the directory (or directories) and restart the script if there are any changes.
  43. ## Manual restarting
  44. Whilst nodemon is running, if you need to manually restart your application, instead of stopping and restart nodemon, you can type `rs` with a carriage return, and nodemon will restart your process.
  45. ## Config files
  46. nodemon supports local and 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 <file>` option.
  47. The specificity is as follows, so that a command line argument will always override the config file settings:
  48. - command line arguments
  49. - local config
  50. - global config
  51. A config file can take any of the command line arguments as JSON key values, for example:
  52. ```json
  53. {
  54. "verbose": true,
  55. "ignore": ["*.test.js", "fixtures/*"],
  56. "execMap": {
  57. "rb": "ruby",
  58. "pde": "processing --sketch={{pwd}} --run"
  59. }
  60. }
  61. ```
  62. The above `nodemon.json` file might be my global config so that I have support for ruby files and processing files, and I can run `nodemon demo.pde` and nodemon will automatically know how to run the script even though out of the box support for processing scripts.
  63. A further example of options can be seen in [sample-nodemon.md](https://github.com/remy/nodemon/blob/master/doc/sample-nodemon.md)
  64. ### package.json
  65. If you want to keep all your package configurations in one place, nodemon supports using `package.json` for configuration.
  66. Specify the config in the same format as you would for a config file but under `nodemonConfig` in the `package.json` file, for example, take the following `package.json`:
  67. ```json
  68. {
  69. "name": "nodemon",
  70. "homepage": "http://nodemon.io",
  71. "...": "... other standard package.json values",
  72. "nodemonConfig": {
  73. "ignore": ["test/*", "docs/*"],
  74. "delay": 2500
  75. }
  76. }
  77. ```
  78. Note that if you specify a `--config` file or provide a local `nodemon.json` any `package.json` config is ignored.
  79. *This section needs better documentation, but for now you can also see `nodemon --help config` ([also here](https://github.com/remy/nodemon/blob/master/doc/cli/config.txt))*.
  80. ## Using nodemon as a module
  81. Please see [doc/requireable.md](doc/requireable.md)
  82. ## Using nodemon as child process
  83. Please see [doc/events.md](doc/events.md#Using_nodemon_as_child_process)
  84. ## Running non-node scripts
  85. nodemon can also be used to execute and monitor other programs. nodemon will read the file extension of the script being run and monitor that extension instead of `.js` if there's no `nodemon.json`:
  86. ```bash
  87. nodemon --exec "python -v" ./app.py
  88. ```
  89. Now nodemon will run `app.py` with python 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.
  90. ### Default executables
  91. 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 default by nodemon.
  92. To add support for nodemon to know about the `.pl` extension (for Perl), the `nodemon.json` file would add:
  93. ```json
  94. {
  95. "execMap": {
  96. "pl": "perl"
  97. }
  98. }
  99. ```
  100. Now running the following, nodemon will know to use `perl` as the executable:
  101. ```bash
  102. nodemon script.pl
  103. ```
  104. It's generally recommended to use the global `nodemon.json` to add your own `execMap` options. However, if there's a common default that's missing, this can be merged in to the project so that nodemon supports it by default, by changing [default.js](https://github.com/remy/nodemon/blob/master/lib/config/defaults.js) and sending a pull request.
  105. ## Monitoring multiple directories
  106. By default nodemon monitors the current working directory. If you want to take control of that option, use the `--watch` option to add specific paths:
  107. ```bash
  108. nodemon --watch app --watch libs app/server.js
  109. ```
  110. Now nodemon will only restart if there are changes in the `./app` or `./libs` directory. By default nodemon will traverse sub-directories, so there's no need in explicitly including sub-directories.
  111. Don't use unix globbing to pass multiple directories, e.g `--watch ./lib/*`, it won't work. You need a `--watch` flag per directory watched.
  112. ## Specifying extension watch list
  113. By default, nodemon looks for files with the `.js`, `.mjs`, `.coffee`, `.litcoffee`, and `.json` extensions. If you use the `--exec` option and monitor `app.py` nodemon will monitor files with the extension of `.py`. However, you can specify your own list with the `-e` (or `--ext`) switch like so:
  114. ```bash
  115. nodemon -e js,pug
  116. ```
  117. Now nodemon will restart on any changes to files in the directory (or subdirectories) with the extensions `.js`, `.pug`.
  118. ## Ignoring files
  119. By default, nodemon will only restart when a `.js` JavaScript file changes. In some cases you will want to ignore some specific files, directories or file patterns, to prevent nodemon from prematurely restarting your application.
  120. This can be done via the command line:
  121. ```bash
  122. nodemon --ignore lib/ --ignore tests/
  123. ```
  124. Or specific files can be ignored:
  125. ```bash
  126. nodemon --ignore lib/app.js
  127. ```
  128. Patterns can also be ignored (but be sure to quote the arguments):
  129. ```bash
  130. nodemon --ignore 'lib/*.js'
  131. ```
  132. Note that by default, nodemon will ignore the `.git`, `node_modules`, `bower_components`, `.nyc_output`, `coverage` and `.sass-cache` directories and *add* your ignored patterns to the list. If you want to indeed watch a directory like `node_modules`, you need to [override the underlying default ignore rules](https://github.com/remy/nodemon/blob/master/faq.md#overriding-the-underlying-default-ignore-rules).
  133. ## Application isn't restarting
  134. 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.
  135. Via the CLI, use either `--legacy-watch` or `-L` for short:
  136. ```bash
  137. nodemon -L
  138. ```
  139. Though this should be a last resort as it will poll every file it can find.
  140. ## Delaying restarting
  141. In some situations, you may want to 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 and it's taking some number of seconds, this could cause your app to restart multiple times unnecessarily.
  142. To add an extra throttle, or delay restarting, use the `--delay` command:
  143. ```bash
  144. nodemon --delay 10 server.js
  145. ```
  146. For more precision, milliseconds can be specified. Either as a float:
  147. ```bash
  148. nodemon --delay 2.5 server.js
  149. ```
  150. Or using the time specifier (ms):
  151. ```bash
  152. nodemon --delay 2500ms server.js
  153. ```
  154. The delay figure is number of seconds (or milliseconds, if specified) to delay before restarting. So nodemon will only restart your app the given number of seconds after the *last* file change.
  155. If you are setting this value in `nodemon.json`, the value will always be interpreted in milliseconds. E.g., the following are equivalent:
  156. ```bash
  157. nodemon --delay 2.5
  158. {
  159. "delay": 2500
  160. }
  161. ```
  162. ## Gracefully reloading down your script
  163. It is possible to have nodemon send any signal that you specify to your application.
  164. ```bash
  165. nodemon --signal SIGHUP server.js
  166. ```
  167. Your application can handle the signal as follows.
  168. ```js
  169. process.once("SIGHUP", function () {
  170. reloadSomeConfiguration();
  171. })
  172. ```
  173. Please note that nodemon will send this signal to every process in the process tree.
  174. If you are using `cluster`, then each workers (as well as the master) will receive the signal. If you wish to terminate all workers on receiving a `SIGHUP`, a common pattern is to catch the `SIGHUP` in the master, and forward `SIGTERM` to all workers, while ensuring that all workers ignore `SIGHUP`.
  175. ```js
  176. if (cluster.isMaster) {
  177. process.on("SIGHUP", function () {
  178. for (const worker of Object.values(cluster.workers)) {
  179. worker.process.kill("SIGTERM");
  180. }
  181. });
  182. } else {
  183. process.on("SIGHUP", function() {})
  184. }
  185. ```
  186. ## Controlling shutdown of your script
  187. nodemon sends a kill signal to your application when it sees a file update. If you need to clean up on shutdown inside your script you can capture the kill signal and handle it yourself.
  188. The following example will listen once for the `SIGUSR2` signal (used by nodemon to restart), run the clean up process and then kill itself for nodemon to continue control:
  189. ```js
  190. process.once('SIGUSR2', function () {
  191. gracefulShutdown(function () {
  192. process.kill(process.pid, 'SIGUSR2');
  193. });
  194. });
  195. ```
  196. Note that the `process.kill` is *only* called once your shutdown jobs are complete. Hat tip to [Benjie Gillam](http://www.benjiegillam.com/2011/08/node-js-clean-restart-and-faster-development-with-nodemon/) for writing this technique up.
  197. ## Triggering events when nodemon state changes
  198. If you want growl like notifications when nodemon restarts or to trigger an action when an event happens, then you can either `require` nodemon or add event actions to your `nodemon.json` file.
  199. For example, to trigger a notification on a Mac when nodemon restarts, `nodemon.json` looks like this:
  200. ```json
  201. {
  202. "events": {
  203. "restart": "osascript -e 'display notification \"app restarted\" with title \"nodemon\"'"
  204. }
  205. }
  206. ```
  207. A full list of available events is listed on the [event states wiki](https://github.com/remy/nodemon/wiki/Events#states). Note that you can bind to both states and messages.
  208. ## Pipe output to somewhere else
  209. ```js
  210. nodemon({
  211. script: ...,
  212. stdout: false // important: this tells nodemon not to output to console
  213. }).on('readable', function() { // the `readable` event indicates that data is ready to pick up
  214. this.stdout.pipe(fs.createWriteStream('output.txt'));
  215. this.stderr.pipe(fs.createWriteStream('err.txt'));
  216. });
  217. ```
  218. ## Using nodemon in your gulp workflow
  219. Check out the [gulp-nodemon](https://github.com/JacksonGariety/gulp-nodemon) plugin to integrate nodemon with the rest of your project's gulp workflow.
  220. ## Using nodemon in your Grunt workflow
  221. Check out the [grunt-nodemon](https://github.com/ChrisWren/grunt-nodemon) plugin to integrate nodemon with the rest of your project's grunt workflow.
  222. ## Pronunciation
  223. > nodemon, is it pronounced: node-mon, no-demon or node-e-mon (like pokémon)?
  224. Well...I've been asked this many times before. I like that I've been asked this before. There's been bets as to which one it actually is.
  225. The answer is simple, but possibly frustrating. I'm not saying (how I pronounce it). It's up to you to call it as you like. All answers are correct :)
  226. ## Design principles
  227. - Fewer flags is better
  228. - Works across all platforms
  229. - Fewer features
  230. - Let individuals build on top of nodemon
  231. - Offer all CLI functionality as an API
  232. - Contributions must have and pass tests
  233. Nodemon is not perfect, and CLI arguments has sprawled beyond where I'm completely happy, but perhaps it can be reduced a little one day.
  234. ## FAQ
  235. See the [FAQ](https://github.com/remy/nodemon/blob/master/faq.md) and please add your own questions if you think they would help others.
  236. ## Backers
  237. Thank you to all [our backers](https://opencollective.com/nodemon#backer)! 🙏
  238. [![nodemon backers](https://opencollective.com/nodemon/backers.svg?width=890)](https://opencollective.com/nodemon#backers)
  239. ## Sponsors
  240. Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Sponsor this project today ❤️](https://opencollective.com/nodemon#sponsor)
  241. <div style="overflow: hidden; margin-bottom: 80px;">
  242. <a href="https://mixmax.com"><img style="margin: 12px; float: left" src="https://user-images.githubusercontent.com/13700/35731622-421d4466-080e-11e8-8ddc-11c70e1cd79e.png" width="120"></a>
  243. <a href="https://www.topratedcasinosites.co.uk/"><img style="margin: 12px; float: left" alt="topratedcasinosites.co.uk" src="https://images.opencollective.com/top-rated-casino-sites/1bf7c97/logo/256.png" width="120"></a>
  244. <a href="https://www.najlepszeplatformyforex.pl/blog/broker-xtb/"><img style="margin: 12px; float: left" src="https://user-images.githubusercontent.com/13700/106011732-a72b2580-60b2-11eb-9d6a-24bf958de95d.png" width="120"></a>
  245. <a href="https://www.auscasinos.com/new"><img style="margin: 12px; float: left" src="https://images.opencollective.com/auscasinos/8df0f47/logo/256.png" style="object-fit: contain; margin: 12px; margin-top:20px" height="120" width="120"></a><a href="https://www.casinoenvivo.com/blackjack"><img style="margin: 12px; float: left" src="https://images.opencollective.com/casino-en-vivo/1340a53/logo/256.png" style="object-fit: contain; margin: 12px; margin-top:20px" height="120" width="120"></a><a href="https://kasynohex.com/"><img src="https://images.opencollective.com/kasynohex-com/b25daf6/logo/256.png" style="object-fit: contain; float: left; margin:12px" height="120" width="120"></a><a href="https://netticasinohex.com/"><img src="https://images.opencollective.com/netticasinohex-com/71d7417/logo/256.png" style="object-fit: contain; float: left; margin:12px" height="120" width="120"></a><a href="https://aussiecasinohex.com/"><img src="https://images.opencollective.com/aussiecasinohex/923df37/logo/256.png" style="object-fit: contain; float: left; margin:12px" height="120" width="120"></a><a href="https://hollandsegokken.nl/"><img src="https://images.opencollective.com/hollandsegokken-nl/7a3d90c/logo/256.png" style="object-fit: contain; float: left; margin:12px" height="120" width="120"></a><a href="https://cryptocasinos.com/"><img src="https://images.opencollective.com/cryptocasinos/99b168e/logo/256.png" style="object-fit: contain; float: left; margin:12px" height="120" width="120"></a><a href="https://mtltimes.ca/life/11-best-real-money-canadian-online-casinos-revealed-after-months-of-testing/"><img src="https://images.opencollective.com/mtl-times/b2736b8/logo/256.png" style="object-fit: contain; float: left; margin:12px" height="120" width="120"></a><a href="https://www.casinoonlineaams.com/"><img src="https://images.opencollective.com/casinoonlineaamscom/da74236/logo/256.png" style="object-fit: contain; float: left; margin:12px" height="120" width="120"></a><a href="https://slotokingua.com/"><img src="https://images.opencollective.com/slotoking-casino-ukraine/f4920ae/logo/256.png" style="object-fit: contain; float: left; margin:12px" height="120" width="120"></a><a href="https://gamblizardcanada.com/free-spins/"><img src="https://images.opencollective.com/gamblizardcanada_com/1aa20b9/logo/256.png" style="object-fit: contain; float: left; margin:12px" height="120" width="120"></a><a href="https://anbefaltcasino.com/"><img src="https://images.opencollective.com/anbefaltcasino-com/ab21410/logo/256.png" style="object-fit: contain; float: left; margin:12px" height="120" width="120"></a><a href="https://www.bitcoinbuster.com/"><img src="https://images.opencollective.com/bitcoinbuster-com/858a895/logo/256.png" style="object-fit: contain; float: left; margin:12px" height="120" width="120"></a><a href="https://www.eldinamo.cl/entretencion/2021/06/08/los-cinco-mejores-casinos-online-en-chile-para-2021/"><img src="https://images.opencollective.com/eldinamo/de50164/logo/256.png" style="object-fit: contain; float: left; margin:12px" height="120" width="120"></a><a href="https://casinosters.com/minimum-deposit-casinos/"><img src="https://images.opencollective.com/casinosters-com/c7fbffd/logo/256.png" style="object-fit: contain; float: left; margin:12px" height="120" width="120"></a><a href="https://www.elespectador.com/contenido-patrocinado/ruleta-en-vivo-en-espana-los-mejores-casinos-segun-su-popularidad/"><img src="https://images.opencollective.com/espectador/7cde7f5/logo/256.png" style="object-fit: contain; float: left; margin:12px" height="120" width="120"></a>
  246. </div>
  247. # License
  248. MIT [http://rem.mit-license.org](http://rem.mit-license.org)