Can pm2 ecosystem support promise config
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
Hi, I am using pm2 start ecosystem.config.js to start my multiple express projects, I use detect-port in each express project to avoid using used ports. Because free port is a dynamic number, so I want to show port in App name when I run pm2 list
┌──────────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ watching │
├──────────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼────────┼──────────┤
│ script │ 0 │ fork │ 33473 │ online │ 4 │ 6h │ 0% │ 0 B │ disabled │
│ specify port │ 12 │ fork │ 35716 │ online │ 0 │ 2h │ 0% │ 0 B │ disabled │
└──────────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴────────┴──────────┘
I searched some issues, the only way I found doing this is change the name before run pm2 start ecosystem.config.js.
const apps = [
{
name:'specify port',
script : "app.js",
},
{
name:'script',
script : "web.js"
}
];
module.exports = apps;
So if pm2 can support promise config, my code can look like this:
const detect = require('detect-port');
function getPorts(basePort, number) {
let ports = [];
return new Promise((resolve)=>{
const cb = (err, _port) => {
if (err) {
console.log(err);
}
ports.push(_port)
if(ports.length<number){
detect(_port+1, cb)
}else {
resolve(ports)
}
}
detect(basePort, cb);
})
}
const apps = [
{
name:'specify port',
script : "app.js",
},
{
name:'script',
script : "web.js"
}
];
function getApp() {
return new Promise((resolve)=>{
getPorts(3000, apps.length).then((data)=>{
const appCopy = apps.map((v,k)=>{
return Object.assign(v,{name:v.name+data[k]})
})
resolve(appCopy)
})
})
}
module.exports = getApp()
Or can you give me other suggestions, thanks.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how pm2 start ecosystem.config.js loads and validates the exported configuration. Define how a promise-returning config should be awaited and how generated app names should appear in pm2 list; the issue does not identify existing files or tests for this behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100