forked from remy/nodemon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
84 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,55 @@ | ||
# Nodemon as a required module | ||
|
||
Note that the way that nodemon is written, it is expected that nodemon is only | ||
used once. | ||
Nodemon (as of 1.0.0) also works as a required module. At present, you can only require nodemon in to your project once (as there are static config variables), but you can re-run with new settings for a different application to monitor. | ||
|
||
This is because nodemon has a single bus for communication. I'd welcome a | ||
re-factor on this recent re-factor, so for now, it's a limitation. Sorry. | ||
By requiring nodemon, you can extend it's functionality. Below is a simple example of using nodemon in your project: | ||
|
||
```js | ||
var nodemon = require('nodemon'); | ||
|
||
nodemon({ | ||
script: 'app.js', | ||
ext: 'js json' | ||
}); | ||
|
||
nodemon.on('start', function () { | ||
console.log('App has started'); | ||
}).on('quit', function () { | ||
console.log('App has quit'); | ||
}).on('restart', function (files) { | ||
console.log('App restarted due to: ', files); | ||
}); | ||
``` | ||
|
||
Nodemon will emit a number of [events](https://github.com/remy/nodemon/blob/master/doc/events.md) by default, and when in verbose mode will also emit a `log` event (which matches what the nodemon cli tool echos). | ||
|
||
## Arguments | ||
|
||
The `nodemon` function takes either an object (that matches the [nodemon config](https://github.com/remy/nodemon#config-files)) or can take a string that matches the arguments that would be used on the command line: | ||
|
||
```js | ||
var nodemon = require('nodemon'); | ||
|
||
nodemon('-e "js json" app.js'); | ||
``` | ||
|
||
## Methods & Properties | ||
|
||
The `nodemon` object also has a few methods and properties. Some are exposed to help with tests, but have been listed here for completeness: | ||
|
||
### 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): | ||
|
||
- `nodemon.on(event, fn)` | ||
- `nodemon.addListener(event, fn)` | ||
- `nodemon.once(event, fn)` | ||
- `nodemon.emit(event)` | ||
- `nodemon.removeAllListners([event])` | ||
|
||
Note: there's no `removeListner` (happy to take a pull request if it's needed). | ||
|
||
### Test utilities | ||
|
||
- `nodemon.reset()` - reverts nodemon's internal state to a clean slate | ||
- `nodemon.config` - a reference to the internal config nodemon uses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters