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:

My Tech Newsletter

Get emails from me about programming & web development. I usually send it once a month