Skip to content

Commit

Permalink
feat: add support for --spawn (#1249)
Browse files Browse the repository at this point in the history
* docs: add sponsors

[skip ci]

* feat: add support for `--spawn`

Fixes #1245

* docs: remove "simply"
  • Loading branch information
remy authored Feb 15, 2018
1 parent 0e08ee2 commit 5e88b04
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 10 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ For use during development of a node.js based application.

nodemon will watch the files in the directory in which nodemon was started, and if any files change, nodemon will automatically restart your node application.

nodemon does **not** require *any* changes to your code or method of development. nodemon simply wraps your node application and keeps an eye on any files that have changed. Remember that nodemon is a replacement wrapper for `node`, think of it as replacing the word "node" on the command line when you run your script.
nodemon does **not** require *any* changes to your code or method of development. nodemon wraps your node application and keeps an eye on any files that have changed. Remember that nodemon is a replacement wrapper for `node`, think of it as replacing the word "node" on the command line when you run your script.

[![NPM version](https://badge.fury.io/js/nodemon.svg)](https://npmjs.org/package/nodemon)
[![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)
Expand Down Expand Up @@ -71,7 +71,7 @@ nodemon was originally written to restart hanging processes such as web servers,

## Manual restarting

Whilst nodemon is running, if you need to manually restart your application, instead of stopping and restart nodemon, you can simply type `rs` with a carriage return, and nodemon will restart your process.
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.

## Config files

Expand All @@ -96,14 +96,14 @@ A config file can take any of the command line arguments as JSON key values, for
}
```

The above `nodemon.json` file might be my global config so that I have support for ruby files and processing files, and I can simply run `nodemon demo.pde` and nodemon will automatically know how to run the script even though out of the box support for processing scripts.
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.

A further example of options can be seen in [sample-nodemon.md](https://github.com/remy/nodemon/blob/master/doc/sample-nodemon.md)

### package.json

If you want to keep all your package configurations in one place, nodemon supports using `package.json` for configuration.
Simply 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`:
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`:

```json
{
Expand Down Expand Up @@ -267,7 +267,7 @@ Note that the `process.kill` is *only* called once your shutdown jobs are comple

## Triggering events when nodemon state changes

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 simply add event actions to your `nodemon.json` file.
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.

For example, to trigger a notification on a Mac when nodemon restarts, `nodemon.json` looks like this:

Expand Down
1 change: 1 addition & 0 deletions doc/cli/options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Execution
--cwd <dir> .............. change into <dir> before running the script
-e, --ext ................ extensions to look for, ie. "js,jade,hbs"
-I, --no-stdin ........... nodemon passes stdin directly to child process
--spawn .................. force nodemon to use spawn (over fork) [node only]
-x, --exec app ........... execute script with "app", ie. -x "python -v"
-- <your args> ........... to tell nodemon stop slurping arguments

Expand Down
2 changes: 1 addition & 1 deletion doc/requireable.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The `nodemon` object also has a few methods and properties. Some are exposed to

### Event handling

This is simply the event emitter bus that exists inside nodemon exposed at the top level module (ie. it's the `events` api):
This is the event emitter bus that exists inside nodemon exposed at the top level module (ie. it's the `events` api):

- `nodemon.on(event, fn)`
- `nodemon.addListener(event, fn)`
Expand Down
8 changes: 6 additions & 2 deletions faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is being added to as common issues occur on the [issues](http://github.com/

This is a working document, and if it makes sense, I'll take pull requests to help make it better.

## nodemon doesn't work with my REPL
# nodemon doesn't work with my REPL

Create an nodemon.json file with the setting:

Expand All @@ -16,6 +16,10 @@ Create an nodemon.json file with the setting:

This will leave the STDIN to your application rather than listening for the `rs` command to restart.

# Strange/failing behaviour starting the (node-based) executable

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

# My script arguments are being taken by nodemon

Use the `--` switch to tell nodemon to ignore all arguments after this point. So to pass `-L` to your script instead of nodemon, use:
Expand Down Expand Up @@ -142,7 +146,7 @@ forever start --uid foo --killSignal=SIGTERM -c 'nodemon --exitcrash' server.js

To test this, you can kill the server.js process and forever will restart it. If you `touch server.js` nodemon will restart it.

To stop the process monitored by forever and nodemon, simply call the following, using the `uid` we assigned above (`foo`):
To stop the process monitored by forever and nodemon, call the following, using the `uid` we assigned above (`foo`):

```bash
forever stop foo
Expand Down
3 changes: 3 additions & 0 deletions lib/cli/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ function nodemonOption(options, arg, eatNext) {
options.noUpdateNotifier = true;
} else

if (arg === '--spawn') {
options.spawn = true;
} else

if (arg === '--dump') {
options.dump = true;
Expand Down
4 changes: 2 additions & 2 deletions lib/config/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function load(settings, options, config, callback) {
}

/**
* Loads the old style nodemonignore files which are simply a list of patterns
* Loads the old style nodemonignore files which is a list of patterns
* in a file to ignore
*
* @param {Object} options nodemon user options
Expand Down Expand Up @@ -210,7 +210,7 @@ function loadFile(options, config, dir, ready) {

function loadPackageJSON(config, ready) {
if (!ready) {
ready = () => {};
ready = () => { };
}

const dir = process.cwd();
Expand Down
1 change: 1 addition & 0 deletions lib/monitor/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function run(options) {
const hasStdio = utils.satisfies('>= 6.4.0 || < 5');

if (
!config.options.spawn &&
firstArg.indexOf('-') === -1 && // don't fork if there's a node arg
firstArg !== 'inspect' && // don't fork it's `inspect` debugger
executable === 'node' && // only fork if node
Expand Down
Binary file added website/nodemon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/sparkpost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5e88b04

Please sign in to comment.