Bird
Raised Fist0
Expressframework~20 mins

PM2 for process management in Express - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
PM2 Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What does PM2 do when you run pm2 start app.js?

When you use PM2 to start an Express app with pm2 start app.js, what is the main behavior PM2 provides?

AIt compiles the app code before running it.
BIt only runs the app once and stops monitoring it.
CIt runs the app and automatically restarts it if it crashes or stops.
DIt runs the app but disables all network connections.
Attempts:
2 left
💡 Hint

Think about what process managers do to keep apps running smoothly.

❓ component_behavior
intermediate
2:00remaining
What is the output of pm2 list after starting two apps?

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

AAn error saying no apps are running.
BA table showing both apps with their status as online and their process IDs.
COnly the first app listed with status online.
DA list of all files in the current directory.
Attempts:
2 left
💡 Hint

PM2 keeps track of all running apps and shows their status.

📝 Syntax
advanced
2:00remaining
Which PM2 command syntax correctly restarts an app named server?

Choose the correct PM2 command to restart an app named server.

Apm2 reload-server
Bpm2 start --restart server
Cpm2 reset server
Dpm2 restart server
Attempts:
2 left
💡 Hint

Look for the PM2 command that explicitly restarts an app by name.

🔧 Debug
advanced
2:00remaining
Why does pm2 logs show no output after starting an app?

You started your Express app with PM2 using pm2 start app.js, but pm2 logs shows no output even when you make requests. What is a likely cause?

AThe app does not print anything to the console; logs are empty.
BPM2 logs command only shows errors, not normal output.
CPM2 was not installed correctly and cannot show logs.
DThe app crashed immediately and stopped logging.
Attempts:
2 left
💡 Hint

Think about what your app prints to the console and what PM2 captures.

❓ lifecycle
expert
2:00remaining
What happens when you run pm2 save and then reboot the server?

After starting your Express app with PM2, you run pm2 save and then reboot your server. What is the expected behavior after reboot?

APM2 automatically restarts all saved apps on reboot without manual commands.
BPM2 forgets all apps and you must start them again manually.
CPM2 deletes the saved list and stops running after reboot.
DPM2 restarts apps but only if you run <code>pm2 resurrect</code> manually.
Attempts:
2 left
💡 Hint

Consider what pm2 save does and how PM2 integrates with system startup.

Practice

(1/5)
1. What is the main purpose of using PM2 with an Express application?
easy
A. To write the Express app code faster
B. To style the Express app's frontend
C. To keep the app running continuously without manual restarts
D. To create database schemas automatically

Solution

  1. Step 1: Understand PM2's role

    PM2 is a process manager that keeps Node.js apps running smoothly by restarting them if they crash or stop.
  2. Step 2: Identify its use with Express

    Using PM2 with Express ensures the server stays online without manual restarts after crashes or updates.
  3. Final Answer:

    To keep the app running continuously without manual restarts -> Option C
  4. Quick Check:

    PM2 manages app uptime = B [OK]
Hint: PM2 keeps your app alive automatically [OK]
Common Mistakes:
  • Thinking PM2 helps with frontend styling
  • Confusing PM2 with code writing tools
  • Assuming PM2 manages databases
2. Which of the following is the correct command to start an Express app named app.js using PM2?
easy
A. pm2 run app.js
B. pm2 start app.js
C. pm2 launch app.js
D. pm2 execute app.js

Solution

  1. Step 1: Recall PM2 start command

    The correct PM2 command to launch an app is pm2 start <file>.
  2. Step 2: Match the command with options

    Among the options, only pm2 start app.js matches the correct syntax.
  3. Final Answer:

    pm2 start app.js -> Option B
  4. Quick Check:

    Start app with 'pm2 start' = D [OK]
Hint: Use 'pm2 start' to launch apps [OK]
Common Mistakes:
  • Using 'pm2 run' which is invalid
  • Confusing 'launch' or 'execute' as PM2 commands
  • Omitting the 'start' keyword
3. Given the following PM2 commands run in order:
pm2 start app.js --name myapp
pm2 restart myapp
pm2 stop myapp
pm2 delete myapp

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

  1. 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.
  2. Step 2: Determine final state

    After deletion, the app is no longer managed by PM2 and is not running.
  3. Final Answer:

    The app is removed from PM2 process list and not running -> Option D
  4. 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

  1. Step 1: Understand PM2 behavior on crashes

    If the app crashes immediately after start, PM2 will stop it and try to restart repeatedly.
  2. Step 2: Identify common crash reasons

    A syntax error in app.js is a common cause for immediate crash and stop.
  3. Final Answer:

    The app.js file has a syntax error causing it to crash -> Option A
  4. 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

  1. 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.
  2. Step 2: Evaluate options

    --instances 1 runs only one instance.
    --scale and --multi are not valid PM2 options.
  3. Final Answer:

    pm2 start app.js -i max -> Option A
  4. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard