Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mattlyons0 committed Oct 14, 2016
2 parents d4e662b + 2cd85b1 commit 4000424
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 42 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ language: node_js
notifications:
email: false
node_js:
- 6
- 5
- 4
# - iojs-v3
# - iojs-v2
# - iojs-v1
- '0.12'
- '0.10'
before_install:
- npm i -g npm@^2.0.0
Expand Down
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ nodemon does **not** require *any* changes to your code or method of development

# Installation

Either through forking or by using [npm](http://npmjs.org) (the recommended way):
Either through cloning with git or by using [npm](http://npmjs.org) (the recommended way):

npm install -g nodemon

And nodemon will be installed in to your bin path. Note that as of npm v1, you must explicitly tell npm to install globally as nodemon is a command line utility.
And nodemon will be installed globally to your system path.

It is also possible to install locally:

npm install --save-dev nodemon

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`). Additionally, the `npm bin` command can be used to obtain the path to the project's local `.bin` directory.

# Usage

Expand Down Expand Up @@ -63,7 +69,7 @@ Whilst nodemon is running, if you need to manually restart your application, ins

## Config files

nodemon supports local and global configuration files. These are named `nodemon.json` and can be located in the current working directory or in your home directory.
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.

The specificity is as follows, so that a command line argument will always override the config file settings:

Expand Down Expand Up @@ -152,7 +158,7 @@ Patterns can also be ignored (but be sure to quote the arguments):

nodemon --ignore 'lib/*.js'

Note that by default, nodemon will ignore the `.git`, `node_modules`, `bower_components` 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 [overriding the underlying default ignore rules](https://github.com/remy/nodemon/blob/master/faq.md#overriding-the-underlying-default-ignore-rules).
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).

## Application isn't restarting

Expand Down Expand Up @@ -182,6 +188,14 @@ Or using the time specifier (ms):

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:

nodemon --delay 2.5

{
"delay": "2500"
}

## Controlling shutdown of your script

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.
Expand Down Expand Up @@ -250,7 +264,7 @@ Check out the [grunt-nodemon](https://github.com/ChrisWren/grunt-nodemon) plugin

## Pronunciation

> nodemon, is it pronunced: node-mon, no-demon or node-e-mon (like pokémon)?
> nodemon, is it pronounced: node-mon, no-demon or node-e-mon (like pokémon)?
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.

Expand Down
2 changes: 1 addition & 1 deletion doc/cli/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
nodemon can also be configured via a local and global config file:

* $HOME/nodemon.json
* $PWD/nodemon.json
* $PWD/nodemon.json OR --config <file>

All config options in the .json file map 1-to-1 with the CLI options, so a
config could read as:
Expand Down
2 changes: 2 additions & 0 deletions doc/cli/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Options:

--config file ............ alternate nodemon.json config file to use
-e, --ext ................ extensions to look for, ie. js,jade,hbs.
-x, --exec app ........... execute script with "app", ie. -x "python -v".
-w, --watch dir........... watch directory "dir" or files. use once for
Expand Down Expand Up @@ -30,6 +31,7 @@
Examples:

$ nodemon server.js
$ nodemon --config my/custom/nodemon.json server.js
$ nodemon -w ../foo server.js apparg1 apparg2
$ PORT=8000 nodemon --debug-brk server.js
$ nodemon --exec python app.py
Expand Down
4 changes: 2 additions & 2 deletions doc/option-parsing-logic.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

1. Read all CLI arguments
2. Load local config
3. Loal global config
3. Load global config
4. Try backup: package.main
5. Try backup: package.start
6. Try index.js
6. Try index.js
20 changes: 18 additions & 2 deletions faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ $ nodemon app.js -- -L -opt2 -opt3

nodemon will ignore all script arguments after `--` and pass them to your script.

# Can't install nodemon: permission issue

You may need to install nodemon using `sudo` (which isn't recommended, but I understand it's unavoidable in some environemnts). If the install fails with this appearing in the npm error log, then you need the following workaround.

```
gyp WARN EACCES user "root" does not have permission to access the dev dir "<some-local-dir>"
```

Try to re-install adding `--unsafe-perm` to the arguments:

```
sudo npm install -g nodemon --unsafe-perm
```

Ref [#713](https://github.com/remy/nodemon/issues/713)

# Help! My changes aren't being detected!

nodemon (from 1.4.2 onwards) uses [Chokidar](https://www.npmjs.com/package/chokidar) as its underlying watch system.
Expand All @@ -43,7 +59,7 @@ Or via the `nodemon.json`:

```json
{
"legacy-watch": true
"legacyWatch": true
}
```

Expand All @@ -61,7 +77,7 @@ This is because the main script argument (`fixtures/sigint.js` in this case) was

Everything 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.

However, there are defaults in the ignore rules that your rules will be merged with, and not override. To override the see [overriding the underlying default ignore rules](#overriding-the-underlying-default-ignore-rules).
However, 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).

## Overriding the underlying default ignore rules

Expand Down
8 changes: 8 additions & 0 deletions lib/cli/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ function nodemonOption(options, arg, eatNext) {
options.legacyWatch = true;
} else

if (arg === '--polling-interval' || arg === '-P') {
options.pollingInterval = parseInt(eatNext(), 10);
} else

// Depricated as this is "on" by default
if (arg === '--js') {
options.js = true;
Expand All @@ -148,6 +152,10 @@ function nodemonOption(options, arg, eatNext) {
options.hidden = true;
} else

if (arg === '--config') {
options.configFile = eatNext();
} else

if (arg === '--watch' || arg === '-w') {
if (!options.watch) { options.watch = []; }
options.watch.push(eatNext());
Expand Down
4 changes: 3 additions & 1 deletion lib/config/defaults.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var ignoreRoot = require('ignore-by-default').directories()

// default options for config.options
module.exports = {
restartable: 'rs',
Expand All @@ -9,7 +11,7 @@ module.exports = {
// compatible with linux, mac and windows, or make the default.js
// dynamically append the `.cmd` for node based utilities
},
ignoreRoot: ['.git', 'node_modules', 'bower_components', '.sass-cache'],
ignoreRoot: ignoreRoot,
watch: ['*.*'],
stdin: true,
runOnChangeOnly: false,
Expand Down
4 changes: 2 additions & 2 deletions lib/config/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function exec(nodemonOptions, execMap) {
var options = utils.clone(nodemonOptions || {});
var script = path.basename(options.script || '');
var scriptExt = path.extname(script).slice(1);
var extension = options.ext || scriptExt || 'js,json';
var extension = options.ext || (scriptExt ? scriptExt + ',json' : 'js,json');
var execDefined = !!options.exec;

// allows the user to simplify cli usage:
Expand Down Expand Up @@ -155,7 +155,7 @@ function exec(nodemonOptions, execMap) {
// BIG NOTE: user can't do this: nodemon -e *.js
// because the terminal will automatically expand the glob against
// the file system :(
extension = extension.match(/\w+/g).join(',');
extension = (extension.match(/[^,.\s]+/g) || []).join(',');

options.ext = extension;

Expand Down
6 changes: 5 additions & 1 deletion lib/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var config = {
dirs: [],
timeout: 1000,
options: {},
signal: 'SIGUSR2',
};

/**
Expand Down Expand Up @@ -58,6 +59,9 @@ config.load = function (settings, ready) {
}

config.watchInterval = options.watchInterval || null;
if (options['signal']) { // jshint ignore:line
config.signal = options.signal;
}

var cmd = command(config.options);
config.command = {
Expand All @@ -83,4 +87,4 @@ config.load = function (settings, ready) {

config.reset = reset;

module.exports = config;
module.exports = config;
7 changes: 5 additions & 2 deletions lib/config/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ function load(settings, options, config, callback) {
config.loaded = [];
// first load the root nodemon.json
loadFile(options, config, utils.home, function (options) {
// then load the user's local nodemon.json
// then load the user's local configuration file
if (settings.configFile) {
options.configFile = path.resolve(settings.configFile);
}
loadFile(options, config, process.cwd(), function (options) {
// Then merge over with the user settings (parsed from the cli).
// Note that merge protects and favours existing values over new values,
Expand Down Expand Up @@ -165,7 +168,7 @@ function loadFile(options, config, dir, ready) {
return callback({});
}

var filename = path.join(dir, 'nodemon.json');
var filename = options.configFile || path.join(dir, 'nodemon.json');
fs.readFile(filename, 'utf8', function (err, data) {
if (err) {
return callback({});
Expand Down
21 changes: 12 additions & 9 deletions lib/monitor/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ function run(options) {
var stdio = ['pipe', 'pipe', 'pipe'];

if (config.options.stdout) {
stdio = ['pipe', process.stdout, process.stderr];
stdio = ['pipe',
process.stdout,
process.stderr,];
}

var sh = 'sh';
Expand Down Expand Up @@ -128,20 +130,20 @@ function run(options) {
// In case we killed the app ourselves, set the signal thusly
if (killedAfterChange) {
killedAfterChange = false;
signal = 'SIGUSR2';
signal = config.signal;
}
// this is nasty, but it gives it windows support
if (utils.isWindows && signal === 'SIGTERM') {
signal = 'SIGUSR2';
signal = config.signal;
}

if (signal === 'SIGUSR2' || code === 0) {
if (signal === config.signal || code === 0) {
// this was a clean exit, so emit exit, rather than crash
debug('bus.emit(exit) via SIGUSR2');
debug('bus.emit(exit) via ' + config.signal);
bus.emit('exit');

// exit the monitor, but do it gracefully
if (signal === 'SIGUSR2') {
if (signal === config.signal) {
return restart();
} else if (code === 0) { // clean exit - wait until file change to restart
if (runCmd) {
Expand Down Expand Up @@ -199,7 +201,7 @@ function run(options) {
/* Now kill the entire subtree of processes belonging to nodemon */
var oldPid = child.pid;
if (child) {
kill(child, 'SIGUSR2', function () {
kill(child, config.signal, function () {
// this seems to fix the 0.11.x issue with the "rs" restart command,
// though I'm unsure why. it seems like more data is streamed in to
// stdin after we close.
Expand Down Expand Up @@ -227,7 +229,8 @@ function run(options) {
// connect stdin to the child process (options.stdin is on by default)
if (options.stdin) {
process.stdin.resume();
process.stdin.setEncoding('utf8');
// FIXME decide whether or not we need to decide the encoding
// process.stdin.setEncoding('utf8');
process.stdin.pipe(child.stdin);

bus.once('exit', function () {
Expand Down Expand Up @@ -264,7 +267,7 @@ function kill(child, signal, callback) {
// spawning processes like `coffee` under the `--debug` flag, it'll spawn
// it's own child, and that can't be killed by nodemon, so psTree gives us
// an array of PIDs that have spawned under nodemon, and we send each the
// SIGUSR2 signal, which fixes #335
// configured signal (defaul: SIGUSR2) signal, which fixes #335
psTree(child.pid, function (err, kids) {
spawn('kill', ['-s', signal, child.pid].concat(kids.map(function (p) {
return p.PID;
Expand Down
11 changes: 6 additions & 5 deletions lib/monitor/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var utils = require('../utils');
var bus = utils.bus;
var match = require('./match');
var watchers = [];
var ready = false;
var debouncedBus;

bus.on('reset', resetWatchers);
Expand All @@ -23,7 +22,6 @@ function resetWatchers() {
watcher.close();
});
watchers = [];
ready = false;
}


Expand All @@ -48,20 +46,23 @@ function watch() {

// don't ignore dotfiles if explicitly watched.
if (!dir.match(dotFilePattern)) {
ignored = new RegExp(ignored.source + dotFilePattern.source);
ignored = [ignored, dotFilePattern];
}

var watcher = chokidar.watch(dir, {
ignored: ignored,
persistent: true,
usePolling: config.options.legacyWatch || false,
interval: config.options.pollingInterval,
});

watcher.ready = false;

var total = 0;

watcher.on('change', filterAndRestart);
watcher.on('add', function (file) {
if (ready) {
if (watcher.ready) {
return filterAndRestart(file);
}

Expand All @@ -70,7 +71,7 @@ function watch() {
debug('watching dir: %s', file);
});
watcher.on('ready', function () {
ready = true;
watcher.ready = true;
resolve(total);
debugRoot('watch is complete');
});
Expand Down
2 changes: 1 addition & 1 deletion lib/nodemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function nodemon(settings) {
});

// echo out notices about running state
if (config.options.restartable) {
if (config.options.stdin && config.options.restartable) {
// allow nodemon to restart when the use types 'rs\n'
process.stdin.resume();
process.stdin.setEncoding('utf8');
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"reload",
"terminal"
],
"preferGlobal": "true",
"license": "MIT",
"main": "./lib/nodemon",
"scripts": {
Expand All @@ -47,9 +46,10 @@
"semantic-release": "4.3.5"
},
"dependencies": {
"chokidar": "^1.2.0",
"chokidar": "^1.4.3",
"debug": "^2.2.0",
"es6-promise": "^3.0.2",
"ignore-by-default": "^1.0.0",
"lodash.defaults": "^3.1.2",
"minimatch": "^3.0.0",
"ps-tree": "^1.0.1",
Expand Down
Loading

0 comments on commit 4000424

Please # to comment.