diff --git a/examples/list-multiple.js b/examples/list-multiple.js new file mode 100644 index 00000000..e24a6bc4 --- /dev/null +++ b/examples/list-multiple.js @@ -0,0 +1,37 @@ +var path = require('path'), + async = require('async'), + forever = require('../lib/forever'); + +function startServer (port, next) { + var child = new (forever.Monitor) (script, { + options: [ '--port', port], + silent: true + }); + + child.start(); + child.on('start', function (_, data) { + console.log('Forever process running server.js on ' + port); + next(null, child); + }); +} + +// Array config data +var script = path.join(__dirname, 'server.js'), + ports = [8080, 8081, 8082]; + +async.map(ports, startServer, function (err, monitors) { + forever.startServer(monitors, function () { + // + // Now that the server has started, run `forever.list()` + // + forever.list(false, function (err, data) { + if (err) { + console.log('Error running `forever.list()`'); + console.dir(err); + } + + console.log('Data returned from `forever.list()`'); + console.dir(data) + }) + }); +}); \ No newline at end of file