util.parseArgs

noun

say it: “yoo-TIL dot PARS-argz” /juˈtɪl dɑt ˈpɑrs ɑrɡz/

A function built into Node that reads a command's named options, such as --runner Leo, with their short forms and defaults.

What does util.parseArgs do?

util.parseArgs is Node's built-in function for reading a command's options, such as --runner Leo or the short -r Leo. You list each option with its type, short letter and default, and it hands back their values.

import { parseArgs } from "node:util";

// node log.js -r Leo
const { values } = parseArgs({
  options: {
    runner: { type: "string", short: "r" },
    week: { type: "string", default: "2026-11-02" },
  },
});
console.log(values.runner, values.week); // Leo 2026-11-02

In a sentence

  • “util.parseArgs throws an error for an option it doesn't know, so a typo doesn't slip through.”
  • “With util.parseArgs, the training log accepts both --runner Leo and -r Leo.”

Level: Journeyman · More Node.js terms at this level

Updated