How to pass a parameter when executing a node.js script?
How to pass a parameter when executing a node.js script?
452
29-Apr-2023
Updated on 01-May-2023
Aryan Kumar
01-May-2023You 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:
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.