Created
September 26, 2023 00:20
-
-
Save floydnoel/5f47671ca53f382b29a872e605ec19d9 to your computer and use it in GitHub Desktop.
Code snippet to parse Node.js arguments (with an equal sign) into a dictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const args = process.argv | |
.filter((arg) => arg.includes("=")) | |
.reduce((acc, cur) => { | |
let split = cur.split("="); | |
acc[split[0]] = split[1]; | |
return acc; | |
}, {}); | |
console.log(args); | |
// run command: node parse-node-args.js foo=bar baz=qux | |
// output: { foo: 'bar', baz: 'qux' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment