What is the state of the app after these commands?
medium
A. The app is running but without a name
B. The app is stopped but still managed by PM2
C. The app is running with the name 'myapp'
D. The app is removed from PM2 process list and not running
Solution
Step 1: Analyze each command effect
pm2 start app.js --name myapp starts the app named 'myapp'. pm2 restart myapp restarts it. pm2 stop myapp stops the app but keeps it in PM2 list. pm2 delete myapp removes the app from PM2 list and stops it completely.
Step 2: Determine final state
After deletion, the app is no longer managed by PM2 and is not running.
Final Answer:
The app is removed from PM2 process list and not running -> Option D
Quick Check:
Delete removes app from PM2 = A [OK]
Hint: Delete removes app from PM2 and stops it [OK]
Common Mistakes:
Thinking stop deletes the app from PM2
Assuming restart keeps app stopped
Confusing app running state after delete
4. You tried to start your Express app with PM2 using pm2 start app.js, but it immediately stops. Which of the following is the most likely cause?
medium
A. The app.js file has a syntax error causing it to crash
B. PM2 does not support Express apps
C. You need to use pm2 run instead of pm2 start
D. The app.js file is missing the package.json
Solution
Step 1: Understand PM2 behavior on crashes
If the app crashes immediately after start, PM2 will stop it and try to restart repeatedly.
Step 2: Identify common crash reasons
A syntax error in app.js is a common cause for immediate crash and stop.
Final Answer:
The app.js file has a syntax error causing it to crash -> Option A
Quick Check:
Crash causes immediate stop = C [OK]
Hint: Check app.js syntax if PM2 stops immediately [OK]
Common Mistakes:
Believing PM2 can't run Express apps
Using wrong PM2 commands like 'run'
Thinking package.json is required to start app.js
5. You want to run multiple instances of your Express app using PM2 to improve performance on a multi-core server. Which command correctly achieves this?
hard
A. pm2 start app.js -i max
B. pm2 start app.js --instances 1
C. pm2 start app.js --scale 4
D. pm2 start app.js --multi 4
Solution
Step 1: Understand PM2 instance options
PM2 uses -i or --instances to specify how many app instances to run. Using -i max runs as many instances as CPU cores.
Step 2: Evaluate options
--instances 1 runs only one instance. --scale and --multi are not valid PM2 options.
Final Answer:
pm2 start app.js -i max -> Option A
Quick Check:
Use '-i max' for multi-core instances = A [OK]
Hint: Use '-i max' to run all CPU cores [OK]
Common Mistakes:
Using invalid options like --scale or --multi
Setting instances to 1 for multi-core use
Confusing PM2 flags for scaling
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.