Dev Helpers

Node.js / Command line options

Capture positional arguments

Dev Helpers · September 21, 2026

Process arguments include runtime and entry-point information before user arguments. Slice off those positions before interpreting input.

Worked example

import { parseArgs } from "node:util";
console.log(
  parseArgs({ args: ["build", "main"], allowPositionals: true }).positionals,
);

Result

[ 'build', 'main' ]

Implementation notes

Quoted shell arguments arrive as one value after the shell processes the command. Avoid splitting the strings a second time unless your application defines another format.

Try it yourself

Run the same script with one quoted argument containing a space.

Open the Node.js example →

Editorial date September 21, 2026 · Published December 6, 2026

Related articles

Safely parse malformed input

Parsing user-provided JSON needs a failure path. Successful parsing alone does not establish that the result has the expected shape.

Checksum bytes with CRC32

CRC32 is useful for detecting accidental changes to a byte sequence. Record the input encoding so different producers compute the same checksum.

Attach details to a mark

Performance marks can carry details about the operation they describe. Small stable identifiers are easier to aggregate than large payloads.