---
source: https://iinventedlight.com/library/notes/node-util-parseargs.md
title: "Node.js util.parseArgs: parse command-line flags"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (Node.js API docs); MIT (nodejs/node (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Node.js API docs, Util - util.parseArgs; nodejs/node (GitHub), doc/api/util.md. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: node util.parseArgs"
tags: [node, cli, parseargs, argv, flags, util]
client: Librarian
sources:
  - id: S1
    title: "Util - util.parseArgs"
    publisher: Node.js API docs
    url: https://nodejs.org/api/util.html
    accessed: 2026-11-18
    license: "MIT"
  - id: S2
    title: "doc/api/util.md"
    publisher: nodejs/node (GitHub)
    url: https://github.com/nodejs/node/blob/main/doc/api/util.md
    accessed: 2026-11-18
    license: "MIT"
---
# Node.js util.parseArgs: parse command-line flags
**Answer:** Import `parseArgs` from `node:util`, describe each option with a `type` of boolean or string, and read the returned `values` and `positionals`. It is a higher level API for argument parsing than reading `process.argv` yourself.

## Examples

```js
import { parseArgs } from 'node:util';

const { values, positionals } = parseArgs({
  options: {
    verbose: { type: 'boolean', short: 'v' },
    out:     { type: 'string', short: 'o', default: 'dist' },
    tag:     { type: 'string', multiple: true },
    color:   { type: 'boolean' },
  },
  allowPositionals: true,
  allowNegative: true,          // --no-color
});
// node cli.js -v --tag a --tag b --no-color src
// values: { verbose: true, out: 'dist', tag: ['a', 'b'], color: false }
// positionals: ['src']

try {
  parseArgs({ args: ['--nope'], options: {} });
} catch (err) {
  console.error(err.code);      // unknown option
}
```

## Config

| Property | Use |
|---|---|
| `args` | argument strings; default is `process.argv` with execPath and filename removed |
| `options` | keys are the long names of options |
| `strict` | throw on unknown arguments or a type mismatch; default `true` |
| `allowPositionals` | accept positional arguments; default `false` if strict is `true` |
| `allowNegative` | set boolean options to false by prefixing the option name with `--no-` |
| `tokens` | return the parsed tokens for custom behavior |

## Option fields

- `type`: must be either `boolean` or `string`.
- `short`: a single character alias.
- `multiple`: if true, values are collected in an array; otherwise the last value wins.
- `default`: applied only when the option does not appear, and it must match the type.

## Rules

- The result has `values`, a mapping of parsed option names, and `positionals`.
- Short option groups like `-xy` expand to a token for each option.
- With `tokens: true` the returned tokens can be reprocessed, for example to add checks.

## See also

- [node-process-and-console](https://iinventedlight.com/library/notes/node-process-and-console/)
- [node-esm](https://iinventedlight.com/library/notes/node-esm/)

## Claims

- id: C1
  claim: parseArgs is a higher level API than process.argv.
  source: S1
  evidence: "Provides a higher level API for command-line argument parsing than interacting with process.argv directly."

- id: C2
  claim: type must be boolean or string.
  source: S1
  evidence: "Type of argument, which must be either boolean or string ."

- id: C3
  claim: Non-multiple options are last-wins.
  source: S2
  evidence: "values for the option are last-wins."

## Sources

- [S1] Util - util.parseArgs. Node.js API docs. https://nodejs.org/api/util.html . License: MIT. Accessed 2026-11-18.

- [S2] doc/api/util.md. nodejs/node (GitHub). https://github.com/nodejs/node/blob/main/doc/api/util.md . License: MIT. Accessed 2026-11-18.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Node.js API docs, Util - util.parseArgs; nodejs/node (GitHub), doc/api/util.md. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
