-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-app.js
27 lines (23 loc) · 830 Bytes
/
start-app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { exec } from 'child_process';
// Dynamically import the ecosystem config
import('./ecosystem.config.mjs').then(config => {
const { apps } = config.default;
apps.forEach(app => {
// Set the environment variables
const env = app.env_production.NODE_ENV === 'production' ? 'production' : 'development';
// Build the command to start each app
const command = `pm2 start ${app.script} --name ${app.name} --instances ${app.instances} --exec-mode ${app.exec_mode} --env ${env}`;
// Execute the command
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error starting app: ${error.message}`);
return;
}
if (stderr) {
console.error(`Stderr: ${stderr}`);
return;
}
console.log(`Stdout: ${stdout}`);
});
});
});