Node.js: Pass Command Line Arguments

2018-01-12 ·

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:

Copyright © 2018 All rights reserved.
Powered by Kulfon.