Skip to content

Commit

Permalink
chore: Merge branch 'master'
Browse files Browse the repository at this point in the history
* 'master' of github.com:remy/nodemon:
  docs: typo on string #24 & #246 (#1374)
  docs: more docs for nodemon as child process (#1362)
  Update faq.md
  Note about procps on Docker
  fix: in watch, use fully filtered ignore rules
  chore: update stalebot
  • Loading branch information
remy committed Jul 10, 2018
2 parents 73aa13f + 251bc57 commit ec76cad
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/stale.yml
Expand Up @@ -7,7 +7,7 @@ exemptLabels:
- pinned
- security
# Label to use when marking an issue as stale
staleLabel: wontfix
staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as idle and stale because it hasn't
Expand Down
14 changes: 9 additions & 5 deletions README.md
Expand Up @@ -21,7 +21,7 @@ npm install -g nodemon

And nodemon will be installed globally to your system path.

You can also install nodemon as a developement dependency:
You can also install nodemon as a development dependency:

```bash
npm install --save-dev nodemon
Expand Down Expand Up @@ -125,9 +125,13 @@ Note that if you specify a `--config` file or provide a local `nodemon.json` any

Please see [doc/requireable.md](doc/requireable.md)

## Using nodemon as child process

Please see [doc/events.md](doc/events.md#Using_nodemon_as_child_process)

## Running non-node scripts

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`:
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`:

```bash
nodemon --exec "python -v" ./app.py
Expand All @@ -139,7 +143,7 @@ Now nodemon will run `app.py` with python in verbose mode (note that if you're n

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.

To add support for nodemon to know about the .pl extension (for Perl), the nodemon.json file would add:
To add support for nodemon to know about the `.pl` extension (for Perl), the `nodemon.json` file would add:

```json
{
Expand Down Expand Up @@ -177,7 +181,7 @@ By default, nodemon looks for files with the `.js`, `.mjs`, `.coffee`, `.litcoff
nodemon -e js,jade
```

Now nodemon will restart on any changes to files in the directory (or subdirectories) with the extensions .js, .jade.
Now nodemon will restart on any changes to files in the directory (or subdirectories) with the extensions `.js`, `.jade`.

## Ignoring files

Expand Down Expand Up @@ -239,7 +243,7 @@ nodemon --delay 2500ms server.js

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.

If you are setting this value in `nodemon.json`, the value will always be interpretted in milliseconds. E.g., the following are equivalent:
If you are setting this value in `nodemon.json`, the value will always be interpreted in milliseconds. E.g., the following are equivalent:

```bash
nodemon --delay 2.5
Expand Down
18 changes: 18 additions & 0 deletions doc/events.md
Expand Up @@ -47,11 +47,29 @@ nodemon.emit('restart');
nodemon.emit('quit');
```

## Using nodemon as child process

If nodemon is a spawned process, then the child (nodemon) will emit message
events whereby the event argument contains the event type, and instead of
emitting events, you `send` the command:

```js
// using `spawn` as example, can use other functions like `fork`, etc
// https://nodejs.org/api/child_process.html
const { spawn } = require('child_process');

function spawnNodemon() {
const cp = spawn('nodemon', ['path/to/file.js', '--watch', 'path/to/watch'], {
// the important part is the 4th option 'ipc'
// this way `process.send` will be available in the child process (nodemon)
// so it can communicate back with parent process (through `.on()`, `.send()`)
// https://nodejs.org/api/child_process.html#child_process_options_stdio
stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
});

return cp;
}

var app = spawnNodemon();

app.on('message', function (event) {
Expand Down
13 changes: 13 additions & 0 deletions faq.md
Expand Up @@ -260,3 +260,16 @@ sudo npm i -g npm
```

Otherwise see [issue #1124](https://github.com/remy/nodemon/issues/1124) for further suggestions.

## No automatic restart when using Docker volumes [issue #419](https://github.com/remy/nodemon/issues/419#issuecomment-391244911)

Some Node.js Docker images do not seem to have the full suite of filtesystem process utilities that allow `nodemon` to restart automatically when the code in a mounted volume changes. To handle this, and enable automatic restarts without using legacy mode, you can install the [procps](http://procps.sourceforge.net) package.

Here's an example snippet of a Dockerfile:

```
FROM node:8.9.4-wheezy
RUN apt-get update && apt-get install -y procps
```


3 changes: 3 additions & 0 deletions lib/monitor/match.js
Expand Up @@ -154,6 +154,9 @@ function match(files, monitor, ext) {
var prefix = s.slice(0, 1);

if (prefix === '!') {
if (s.indexOf('!' + cwd) === 0) {
return s;
}
return '!**' + (prefix !== path.sep ? path.sep : '') + s.slice(1);
}

Expand Down
7 changes: 6 additions & 1 deletion lib/monitor/watch.js
Expand Up @@ -41,7 +41,12 @@ function watch() {

const promise = new Promise(function (resolve) {
const dotFilePattern = /[/\\]\./;
var ignored = Array.from(rootIgnored);
var ignored = match.rulesToMonitor(
[], // not needed
Array.from(rootIgnored),
config
).map(pattern => pattern.slice(1));

const addDotFile = dirs.filter(dir => dir.match(dotFilePattern));

// don't ignore dotfiles if explicitly watched.
Expand Down

0 comments on commit ec76cad

Please sign in to comment.