Skip to content

Instantly share code, notes, and snippets.

@floydnoel
Created September 26, 2023 00:20
Show Gist options
  • Save floydnoel/5f47671ca53f382b29a872e605ec19d9 to your computer and use it in GitHub Desktop.
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
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