0
0
Node.jsframework~5 mins

process.exit and exit codes in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does process.exit() do in Node.js?

process.exit() stops the Node.js program immediately. It ends the running process.

Click to reveal answer
beginner
What is an exit code in Node.js?

An exit code is a number that tells the system if the program ended successfully or with an error. 0 means success, any other number means an error or special condition.

Click to reveal answer
beginner
How do you specify an exit code with process.exit()?

You pass the exit code as a number inside the parentheses. For example, process.exit(1) ends the program with exit code 1.

Click to reveal answer
beginner
What does process.exit(0) mean?

process.exit(0) means the program ended successfully without errors.

Click to reveal answer
intermediate
Why should you be careful when using process.exit()?

Because it stops the program immediately, it can skip cleanup tasks like saving files or closing connections. Use it only when you want to end the program right away.

Click to reveal answer
What does process.exit(1) indicate?
AProgram ended successfully
BProgram ended with an error
CProgram paused
DProgram restarted
What happens if you call process.exit() without a number?
AProgram continues running
BProgram exits with code 1
CProgram exits with code 0
DProgram throws an error
Which exit code usually means success?
A-1
B1
C100
D0
Why might you avoid using process.exit() in some cases?
AIt can skip important cleanup tasks
BIt slows down the program
CIt causes memory leaks
DIt restarts the program
How do you end a Node.js program with exit code 2?
Aprocess.exit(2)
Bexit(2)
Cprocess.end(2)
DexitCode(2)
Explain what process.exit() does and how exit codes work in Node.js.
Think about how programs tell the system if they ended well or not.
You got /4 concepts.
    Describe why you should be careful when using process.exit() in your Node.js programs.
    Consider what happens if the program stops without finishing important work.
    You got /3 concepts.