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;

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:

Subscribe to My Newsletter

The latest programming-related news, articles and resources - sent to your inbox monthly. Unsubscribe anytime.