0
0
Node.jsframework~20 mins

PM2 for process management in Node.js - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PM2 Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the primary purpose of PM2 in Node.js?

PM2 is a popular tool used with Node.js. What is its main job?

ATo convert Node.js applications into mobile apps automatically.
BTo compile Node.js code into machine language for faster execution.
CTo provide a graphical user interface for writing Node.js code.
DTo manage and keep Node.js applications running smoothly in the background.
Attempts:
2 left
💡 Hint

Think about what helps keep your app alive and restarts it if it crashes.

component_behavior
intermediate
1:30remaining
What happens when you run 'pm2 start app.js'?

Consider you have a Node.js app in app.js. What does the command pm2 start app.js do?

AOnly runs the app once and then stops PM2 automatically.
BStarts the app and keeps it running in the background, restarting if it crashes.
CCompiles <code>app.js</code> into a binary file without running it.
DDeletes <code>app.js</code> after running it once.
Attempts:
2 left
💡 Hint

Think about how PM2 helps keep your app alive even if it crashes.

state_output
advanced
2:00remaining
What is the output of 'pm2 list' after starting two apps?

You started two apps with PM2: pm2 start app1.js and pm2 start app2.js. What will pm2 list show?

AA table listing both apps with their status as 'online' and their process IDs.
BAn error saying no apps are running because PM2 does not track multiple apps.
COnly the first app listed with the second app missing.
DA blank screen with no output.
Attempts:
2 left
💡 Hint

PM2 tracks all apps it manages and shows their status.

🔧 Debug
advanced
2:00remaining
Why does 'pm2 restart app' fail with 'process not found'?

You ran pm2 restart app but got an error: 'process not found'. What is the likely cause?

AThe process name 'app' does not match any running PM2 process names or IDs.
BPM2 is not installed on your system.
CYour Node.js app crashed and cannot be restarted.
DYou need to use <code>pm2 reload app</code> instead of restart.
Attempts:
2 left
💡 Hint

Check the exact process names or IDs PM2 shows in pm2 list.

📝 Syntax
expert
2:30remaining
Which PM2 ecosystem config file is valid for running two apps?

Choose the correct JSON format for a PM2 ecosystem file that runs app1.js and app2.js with names app-one and app-two.

A
{
  "apps": {
    "app-one": "app1.js",
    "app-two": "app2.js"
  }
}
B
}
]  
}"sj.2ppa" :"tpircs" ,"owt-ppa" :"eman"{    
,}"sj.1ppa" :"tpircs" ,"eno-ppa" :"eman"{    
[ :"sppa"  
{
C
{
  "apps": [
    {"name": "app-one", "script": "app1.js"},
    {"name": "app-two", "script": "app2.js"}
  ]
}
D
{
  "apps": [
    {"name": "app-one", "script": "app1.js"},
    {"name": "app-two"}
  ]
}
Attempts:
2 left
💡 Hint

Remember JSON requires double quotes around keys and strings, and arrays use square brackets.