Skip to content

Commit 9dc7bad

Browse files
committed
[doc] Added example about running / listing multiple processes programmatically
1 parent c3fe93a commit 9dc7bad

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

examples/list-multiple.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var path = require('path'),
2+
async = require('async'),
3+
forever = require('../lib/forever');
4+
5+
function startServer (port, next) {
6+
var child = new (forever.Monitor) (script, {
7+
options: [ '--port', port],
8+
silent: true
9+
});
10+
11+
child.start();
12+
child.on('start', function (_, data) {
13+
console.log('Forever process running server.js on ' + port);
14+
next(null, child);
15+
});
16+
}
17+
18+
// Array config data
19+
var script = path.join(__dirname, 'server.js'),
20+
ports = [8080, 8081, 8082];
21+
22+
async.map(ports, startServer, function (err, monitors) {
23+
forever.startServer(monitors, function () {
24+
//
25+
// Now that the server has started, run `forever.list()`
26+
//
27+
forever.list(false, function (err, data) {
28+
if (err) {
29+
console.log('Error running `forever.list()`');
30+
console.dir(err);
31+
}
32+
33+
console.log('Data returned from `forever.list()`');
34+
console.dir(data)
35+
})
36+
});
37+
});

0 commit comments

Comments
 (0)