Search code examples
node.jspm2

Merging/namespacing PM2 apps


There is PM2 configuration, /home/foo/someconfig.json

{
    "apps": [
        {
            "name": "foo-main",
            "script": "./index.js",
        },
        {
            "name": "foo-bar",
            "script": "./bar.js"
        },
        {
            "name": "foo-baz",
            "script": "./baz.js"
        }
    ]
}

Most of the time I want to refer to all of the apps under current namespace, e.g.

pm2 restart foo

instead of doing

pm2 restart foo-main foo-bar foo-baz

Bash brace extension cannot be used because apps may run in Windows.

Doing pm2 restart /home/foo/someconfig.json isn't a good option, because it takes some time to figure out config file path, it may differ between projects and even change its location.

Can foo-* apps be merged into single foo app or be referred altogether in another reasonable way?


Solution

  • pm2 supports regex's since 2.4.0, e.g.

    pm2 restart /^foo-/
    

    If using with the start command, remember to provide the eco system file as first parameter.