I have a web server written in Node.js and I would like to launch with a specific folder. I\'m not sure how to access arguments in JavaScript. I\'m running node like this:>
Here's my 0-dep solution for named arguments:
const args = process.argv
.slice(2)
.map(arg => arg.split('='))
.reduce((args, [value, key]) => {
args[value] = key;
return args;
}, {});
console.log(args.foo)
console.log(args.fizz)
Example:
$ node test.js foo=bar fizz=buzz
bar
buzz
Note: Naturally this will fail when the argument contains a =
. This is only for very simple usage.