简体   繁体   中英

How do I use pm2.start()?

It's my first time with pm2. I am particularly trying to use the programmatic API. Now when I call pm2.start('./app.js'), it doesn't look like the script is executed. In the sample code below, I expect to see "Working" in the console.

app.js

console.log('Working');

index.js

pm2.connect((err) => {
    pm2.start('./app.js', (err, d) => {
    });
});

Am I missing something?

Your code is correct only. PM2 write logs in file instead of console . So You can find logs in app-error.log file or app-out.log file.

var pm2 = require('pm2')

pm2.connect((err) => {
    if(err){
        console.log('ERROR ',err)
    }
    pm2.start('./app.js', (err, d) => {
        console.log('APP STARTED', err, d)
    });
});

You can find the log file path in the console.log('APP STARTED', err, d) output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM