Files
30-seconds-of-code/snippets/get-cmd-args.md
Angelos Chalaris 61200d90c4 Kebab file names
2023-04-27 21:58:35 +03:00

537 B

title, tags, author, cover, firstSeen
title tags author cover firstSeen
Command-line arguments node chalarangelo terminal 2022-04-26T05:00:00-04:00

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']