It's a simple thing to do with a bash, I would just search for $1
it and have the first parameter sent, but with node I have no idea how it works and google
it didn't help me.
If I want to run something like:
node pepe.js "hello"
How do I receive that parameter in my program?
Greetings.
process.argv
is an array containing the command line arguments.The first element (
process.argv[0]
) contains the path to the executable ofnode
, the second element contains the name of the running javascript file, in this casepepe.js
. The following arguments have the values passed by the command line. In this caseprocess.argv[2] === "hola"
.With the following example:
Then running:
You would get the output:
Official Documentation
Salu2