https://github.com/silverwind/rebirth
Restart a node process from within itself
https://github.com/silverwind/rebirth
Last synced: about 1 year ago
JSON representation
Restart a node process from within itself
- Host: GitHub
- URL: https://github.com/silverwind/rebirth
- Owner: silverwind
- License: bsd-2-clause
- Created: 2015-05-14T21:35:15.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2018-06-03T15:37:02.000Z (almost 8 years ago)
- Last Synced: 2024-10-20T01:08:03.674Z (over 1 year ago)
- Language: JavaScript
- Size: 80.1 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rebirth
[](https://www.npmjs.org/package/rebirth) [](https://www.npmjs.org/package/rebirth) [](https://travis-ci.org/silverwind/rebirth)
> Restart a node process from within itself
Restarting is done by spawning a detached copy of the current process and subsequently ending the running process. The new child will be orphaned and parented to PID 1 (init/systemd/launchd).
## Installation
```
$ npm install --save rebirth
```
## Example
```js
const rebirth = require('rebirth');
rebirth();
// process restarts
```
#### Notes:
- To detect if a process was reborn, check if `process.env.REBORN` is `'1'`;
- Standard streams will be inherited by default. When running in a terminal, this means stdout/stderr will still print to that terminal after a restart. If you don't care about these streams, set `opts.stdio = 'ignore'`.
## API
### rebirth([options])
- `options` {Object} Takes the same options as [`child_process.spawn`](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options).
© [silverwind](https://github.com/silverwind), distributed under BSD licence