UNPKG

9.98 kBMarkdownView Raw
1# FAQ
2
3This is being added to as common issues occur on the [issues](http://github.com/remy/nodemon/issues), and where appropriate the answers will be added here.
4
5This is a working document, and if it makes sense, I'll take pull requests to help make it better.
6
7# nodemon doesn't work with my REPL
8
9Create an nodemon.json file with the setting:
10
11```js
12{
13 "restartable": false
14}
15```
16
17This will leave the STDIN to your application rather than listening for the `rs` command to restart.
18
19# Strange/failing behaviour starting the (node-based) executable
20
21By default, nodemon will try to fork your node scripts ([background reading](https://github.com/remy/nodemon/issues/1025)), however, there are some edge cases where that won't suit your needs. Most of the time the default configuration should be fine, but if you want to force nodemon to spawn your node process, use the `--spawn` option.
22
23# My script arguments are being taken by nodemon
24
25Use the `--` switch to tell nodemon to ignore all arguments after this point. So to pass `-L` to your script instead of nodemon, use:
26
27```
28$ nodemon app.js -- -L -opt2 -opt3
29```
30
31nodemon will ignore all script arguments after `--` and pass them to your script.
32
33# Error: "process failed, unhandled exit code (2)"
34
35Nodemon will look for exit signals from the child process it runs. When the exit code is `2`, nodemon throws an error. Typically this is because the arguments are bad for the executing program, but it can also be due other reasons.
36
37For example, mocha@3.x will exit with `2` on failing tests. To handle the exit code in a way that nodemon can consume, manually exit the process, i.e.:
38
39```bash
40nodemon -x 'mocha test/bad.test.js || exit 1'
41```
42
43# Can't install nodemon: permission issue
44
45You may need to install nodemon using `sudo` (which isn't recommended, but I understand it's unavoidable in some environments). If the install fails with this appearing in the npm error log, then you need the following workaround.
46
47```
48gyp WARN EACCES user "root" does not have permission to access the dev dir "<some-local-dir>"
49```
50
51Try to re-install adding `--unsafe-perm` to the arguments:
52
53```
54sudo npm install -g nodemon --unsafe-perm
55```
56
57Ref [#713](https://github.com/remy/nodemon/issues/713)
58
59# Help! My changes aren't being detected!
60
61nodemon (from 1.4.2 onwards) uses [Chokidar](https://www.npmjs.com/package/chokidar) as its underlying watch system.
62
63If you find your files aren't being monitored, either nodemon isn't restarting, or it reports that zero files are being watched, then you may need the polling mode.
64
65To enable polling use the the legacy flag either via the terminal:
66
67```shell
68$ nodemon --legacy-watch
69$ nodemon -L # short alias
70```
71
72Or via the `nodemon.json`:
73
74```json
75{
76 "legacyWatch": true
77}
78```
79
80## nodemon tries to run two scripts
81
82If you see nodemon trying to run two scripts, like:
83
84```
859 Dec 23:52:58 - [nodemon] starting `node ./app.js fixtures/sigint.js`
86```
87
88This is because the main script argument (`fixtures/sigint.js` in this case) wasn't found, and a `package.json`'s main file _was_ found. ie. to solve, double check the path to your script is correct.
89
90## What has precedence, ignore or watch?
91
92Everything under the ignore rule has the final word. So if you ignore the `node_modules` directory, but watch `node_modules/*.js`, then all changed files will be ignored, because any changed .js file in the `node_modules` are ignored.
93
94However, there are defaults in the ignore rules that your rules will be merged with, and not override. To override the ignore rules see [overriding the underlying default ignore rules](#overriding-the-underlying-default-ignore-rules).
95
96## Overriding the underlying default ignore rules
97
98The way the ignore rules work is that your rules are merged with the `ignoreRoot` rules, which contain `['.git', 'node_modules', ...]`. So if you ignore `public`, the ignore rule results in `['.git', 'node_modules', ..., 'public']`.
99
100Say you did want to watch the `node_modules` directory. You have to override the `ignoreRoot`. If you wanted this on a per project basis, add the config to you local `nodemon.json`. If you want it for all projects, add it to `$HOME/nodemon.json`:
101
102```json
103{
104 "ignoreRoot": [".git"]
105}
106```
107
108Now when ignoring `public`, the ignore rule results in `['.git', 'public']`, and nodemon will restart on `node_modules` changes.
109
110## nodemon doesn't work with fedora
111
112Fedora is looking for `nodejs` rather than `node` which is the binary that nodemon kicks off.
113
114A workaround is to make sure that `node` binary exists in the `PATH`:
115
116```bash
117sudo ln -s /usr/bin/nodejs /usr/local/bin/node
118```
119
120Alternatively the `--exec nodejs` option can be used.
121
122Fedora and Ubuntu pakage node as nodejs, because node.dpkg is
123
124> Description-en: Amateur Packet Radio Node program
125> The node program accepts TCP/IP and packet radio network connections and
126> presents users with an interface that allows them to make gateway connections
127> to remote hosts using a variety of amateur radio protocols.
128> They make the binary is nodejs, rather than node. So long as you're not using that Packet Radio Node Program mentioned above the workaround will work.
129
130Thank you [@EvanCarroll](https://github.com/remy/nodemon/issues/68#issuecomment-13672509)
131
132## Using nodemon with forever
133
134If you're using nodemon with [forever](https://github.com/foreverjs/forever) (perhaps in a production environment), you can combine the two together. This way if the script crashes, forever restarts the script, and if there are file changes, nodemon restarts your script. For more detail, see [issue 30](https://github.com/remy/nodemon/issues/30).
135
136To achieve this you need to add the following on the call to `forever`:
137
138* Use forever's `-c nodemon` option to tell forever to run `nodemon` instead of `node`.
139* Include the nodemon `--exitcrash` flag to ensure nodemon exits if the script crashes (or exits unexpectedly).
140* Tell forever to use `SIGTERM` instead of `SIGKILL` when requesting nodemon to stop. This ensures that nodemon can stop the watched node process cleanly.
141* Optionally add the `--uid` parameter, adding a unique name for your process. In the example, the uid is set to `foo`.
142
143```bash
144forever start --uid foo --killSignal=SIGTERM -c 'nodemon --exitcrash' server.js
145```
146
147To test this, you can kill the server.js process and forever will restart it. If you `touch server.js` nodemon will restart it.
148
149To stop the process monitored by forever and nodemon, call the following, using the `uid` we assigned above (`foo`):
150
151```bash
152forever stop foo
153```
154
155This will stop both nodemon and the node process it was monitoring.
156
157Note that I _would not_ recommend using nodemon in a production environment - but that's because I wouldn't want it restart without my explicit instruction.
158
159## What does "verbose" give me?
160
161The `--verbose` (or `-V`) puts nodemon in verbose mode which adds some detail to starting and restarting.
162
163Additional restart information:
164
165* Which nodemon configs are loaded (local and global if found)
166* Which ignore rules are being applied
167* Which file extensions are being watch
168* The process ID of your application (the `child pid`)
169
170For example:
171
172```text
17314 Apr 15:24:58 - [nodemon] v1.0.17
17414 Apr 15:24:58 - [nodemon] reading config /Users/remy/Sites/jsbin-private/nodemon.json
17514 Apr 15:24:58 - [nodemon] to restart at any time, enter `rs`
17614 Apr 15:24:58 - [nodemon] ignoring: /Users/remy/Sites/jsbin-private/.git/**/* node_modules/**/node_modules
17714 Apr 15:24:58 - [nodemon] watching: /Users/remy/Sites/jsbin/views/**/* /Users/remy/Sites/jsbin/lib/**/* ../json/*.json config.dev.json
17814 Apr 15:24:58 - [nodemon] watching extensions: json,js,html
17914 Apr 15:24:58 - [nodemon] starting `node run.js`
18014 Apr 15:24:58 - [nodemon] child pid: 9292
181```
182
183When nodemon detects a change, the following addition information is shown:
184
185* Which file(s) triggered the check
186* Which (if any) rules the file matched to cause a subsequent restart
187* How many rules were matched and out of those rules, how many cause a restart
188* A list of all the files that _successfully_ caused a restart
189
190For example, on `lib/app.js` being changed:
191
192```text
19314 Apr 15:25:56 - [nodemon] files triggering change check: ../jsbin/lib/app.js
19414 Apr 15:25:56 - [nodemon] matched rule: **/Users/remy/Sites/jsbin/lib/**/*
19514 Apr 15:25:56 - [nodemon] changes after filters (before/after): 1/1
19614 Apr 15:25:56 - [nodemon] restarting due to changes...
19714 Apr 15:25:56 - [nodemon] ../jsbin/lib/app.js
198
19914 Apr 15:25:56 - [nodemon] starting `node run.js`
20014 Apr 15:25:56 - [nodemon] child pid: 9556
201```
202
203## My .nodemonignore is being ignored
204
205The new `nodemon.json` supersedes the `.nodemonignore` file, so if you have both, the `.nodemonignore` is not used at all.
206
207Note that if you have a `nodemon.json` in your `$HOME` path, then this will also supersede the old ignore file (and the _legacy_ format config is ignored).
208
209## nodemon does nothing
210
211On Ubuntu globally installed node applications have been found to have no output when they're run. This _seems_ to be an issue with node not being correctly installed (possibly linked to the binary having to be called `nodejs`).
212
213The solution (that's worked in the past) is to install [nvm](https://github.com/creationix/nvm) first and using it to install node, _rather_ than using `apt-get` (or similar tools) to install node directly.
214
215## If nodemon is facing the watch errors (Mac & Linux)
216
217Try the following command on terminal:
218
219```bash
220echo fs.inotify.max_user_watches=582222 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
221```
222
223## Error: Cannot find module 'internal/util/types'
224
225If you see the error `Cannot find module 'internal/util/types'`, the error is solved with a clean npm cache and trying to reinstall the dependency you're working with.
226
227A start is to use the following commands:
228
229```
230sudo npm cache clean --force
231sudo npm i -g npm
232```
233
234Otherwise see [issue #1124](https://github.com/remy/nodemon/issues/1124) for further suggestions.