node-persistent-software
v1.5.1
Published
Spawn a software and keep it running
Downloads
4
Maintainers
Readme
node-persistent-software
Spawn a software and keep it running
Installation
$ npm install node-persistent-software
Doc (extends : asynchronous-eventemitter)
Attributes
maxCountRun: number
max start iterationsuccessCountRun: number
current success start iteration
Constructor
constructor(software: string, args?: Array<string>, options?: object)
=> see spawn documentation
Methods
max(maxIteration: number) : this
change max iterations and reset currentinfinite() : this
no max iteration and reset currentstart() : this
run the software for the first timeend() : this
stop the software and does not restart it
Events
on("error", (err: Error) => void) : this
fire if an error occurs (use try/catch to avoid loop)on("firststart", () => void) : this
fire if the software starts for the first timeon("restart", () => void) : this
fire if the software restartson("start", (child_process: child_process.ChildProcess) => void) : this
fire if the software starts (firststart && restart) => see spawn documentationon("stop", () => void) : this
fire if the software is killedon("end", () => void) : this
fire if the software is killed and cannot be restarted
Examples
Native
const PersistantSoftware = require("node-persistent-software");
new PersistantSoftware("node", [ "-v" ]).on("error", (msg) => {
console.log(msg);
})
.infinite()
.on("firststart", () => {
console.log("node is started for the first time !");
}).on("restart", () => {
console.log("node is started again...");
}).on("start", (child_process) => {
console.log("anyway, node is started.");
})
.on("stop", () => {
console.log("node is stopped, trying to restart...");
}).on("end", () => {
console.log("/!\\ node is stopped and cannot be restarted /!\\");
}).start();
new PersistantSoftware("node", [ "-v" ]).on("error", (err) => {
console.log(err);
})
.max(5)
.on("firststart", () => {
console.log("node is started for the first time !");
}).on("restart", () => {
console.log("node is started again...");
}).on("start", () => {
console.log("anyway, node is started.");
})
.on("stop", () => {
console.log("node is stopped, trying to restart...");
}).on("end", () => {
console.log("/!\\ node is stopped and cannot be restarted /!\\");
}).start();
Typescript
import PersistantSoftware = require("node-persistent-software");
new PersistantSoftware("node", [ "-v" ]).on("error", (err) => {
console.log(err);
})
.infinite();
Tests
$ npm run-script tests