Node.js: Pass Command Line Arguments


2018-01-12 · 1 min read

Use process.argv to read the command line arguments

// app.js
const args = process.argv;
console.log(args);

Run app.js

node app.js a b=2 -c
['node', '/path/to/app.js', 'a', 'b=c', '-c']

There are many packages in the Node.js ecosystem that provide more sophisticated argument parsing: