---
title: "How to pass a parameter when executing a node.js script?"  
description: "How to pass a parameter when executing a node.js script?"  
author: "Revati S Misra"  
published: 2023-04-29  
updated: 2023-05-01  
canonical: https://www.mindstick.com/forum/158086/how-to-pass-a-parameter-when-executing-a-node-js-script  
category: "node.js"  
tags: ["javascript", "node js"]  
reading_time: 1 minute  

---

# How to pass a parameter when executing a node.js script?

How to pass a [parameter](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp) when executing a [node.js](https://www.mindstick.com/articles/1499/upload-and-download-file-in-node-js) [script](https://www.mindstick.com/interview/477/how-can-i-execute-a-php-script-using-command-line)?

## Replies

### Reply by Aryan Kumar

You can pass a parameter when executing a Node.js script by including the parameter as an argument in the command line. Here's an example of how to pass a parameter to a Node.js script:

```javascript
// script.js
console.log(process.argv[2]);
```

In this example, we use the **process.argv** array to access the command line arguments passed to the Node.js process. **process.argv[0]** is the path to the Node.js executable, **process.argv[1]** is the path to the script being executed, and **process.argv[2]** is the first command line argument passed to the script.


---

Original Source: https://www.mindstick.com/forum/158086/how-to-pass-a-parameter-when-executing-a-node-js-script

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
