take arguments from command line in javascript

In Node.js, you can access command line arguments using the process.argv array. The first element of process.argv is the path to Node.js executable, the second element is the path to the script file being executed, and the following elements are the arguments passed in.

Here's an example of how you can access command line arguments in Node.js:

index.tsx
// app.js
console.log(process.argv);
37 chars
3 lines

If you run the script with node app.js arg1 arg2 arg3, the output will be an array of command line arguments as shown below:

index.tsx
[
  '/path/to/node',
  '/path/to/script/app.js',
  'arg1',
  'arg2',
  'arg3'
]
80 chars
8 lines

You can access specific arguments by their index in the process.argv array.

related categories

gistlibby LogSnag