Skip to content

Instantly share code, notes, and snippets.

@souporserious
Created June 25, 2021 05:26
Show Gist options
  • Save souporserious/a1609bea075ebf21d6f6056b00e7eee0 to your computer and use it in GitHub Desktop.
Save souporserious/a1609bea075ebf21d6f6056b00e7eee0 to your computer and use it in GitHub Desktop.
Parse Node args using Object.fromEntries.
const args = Object.fromEntries(
process.argv.slice(2).map((arg) => {
const [key, value] = arg.split('=')
return [key.slice(2), value]
})
)
// input: --port=3000 --out=dist
// output: { port: '3000', out: 'dist' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment