My answer is the same as the answer by @Nikita Ivanov but with pm2. I personally like pm2, which also uses a config file just like forever, but it can be a js, json or yaml file.
// JS File
module.exports = {
apps : [{
name: "bot1",
script: "./bot1.js",
watch: true, // some optional param just for example
env: {
"NODE_ENV": "development",
}, // some optional param just for example
env_production : {
"NODE_ENV": "production"
} // some optional param just for example
},{
name: "bot2",
script: "./bot2.js",
instances: 4, // some optional param just for example
exec_mode: "cluster" // some optional param just for example
}]
}
Now if you do not know the number of scripts there are, it ok. Since it is JS, you can write a script to get the list of all the files in the directory and create an array similar to the one above and use that config for pm2.
module.exports = (function () {
// logic to get all file names and create the 'apps' array
return {
apps: apps
}
})()
Furthermore, you can also use the pm2 npm module and use pm2 as a module in a js script and do this.
See PM2 DOCS for more info.