Command-line arguments – 30 seconds of code

Gets the command-line arguments passed to a Node.js script.

  • Use process.argv to get an array of all command-line arguments.
  • Use Array.prototype.slice() to remove the first two elements (path of the Node.js executable and the file being executed).
const getCmdArgs = () => process.argv.slice(2);

// node my-script.js --name=John --age=30
getCmdArgs(); // ['--name=John', '--age=30']

Would you like to help us improve 30 seconds of code?Take a quick survey

Recommended snippets

  • Checks if the given argument is a duplex (readable and writable) stream.

  • Checks if the given argument is a writable stream.

  • Checks if the given argument is a readable stream.

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Article

Electric vehicles have a dark side too: Blood batteries and child labour

Next Article

World will face at least 560 climate disasters every year by 2030, warns UN

Related Posts