---
title: "What is the command that is used to exit in Node.js?"  
description: "What is the command that is used to exit in Node.js?"  
author: "Revati S Misra"  
published: 2023-04-29  
updated: 2023-05-01  
canonical: https://www.mindstick.com/forum/158087/what-is-the-command-that-is-used-to-exit-in-node-js  
category: "node.js"  
tags: ["javascript", "node js"]  
reading_time: 1 minute  

---

# What is the command that is used to exit in Node.js?

What is the [command](https://www.mindstick.com/blog/178/synchronous-and-asynchronous-command-execution-in-c-sharp-dot-net) that is used to exit in [Node.js](https://www.mindstick.com/articles/1499/upload-and-download-file-in-node-js)?

## Replies

### Reply by Aryan Kumar

In Node.js, the command to exit a program is **process.exit([code])**. The **process.exit()** method exits the current Node.js process with an optional exit code.

The **code** parameter is an integer that represents the exit code. The exit code can be used to indicate the reason for the process exit. A value of **0** indicates successful termination, while non-zero values indicate an error or other non-successful exit.

Here's an example of how to use **process.exit()** to exit a Node.js program:

```javascript
// app.js
console.log('Starting program...');
if (process.argv[2] === 'exit') {
 console.log('Exiting program...');
 process.exit();
}
console.log('Continuing program...');
```

In this example, we use **process.argv** to check if the command line argument is **"exit"**. If it is, we print a message and exit the program using **process.exit()**. If it isn't, we continue with the rest of the program.


---

Original Source: https://www.mindstick.com/forum/158087/what-is-the-command-that-is-used-to-exit-in-node-js

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
