Solution: lb_wc

Node.js·1 min read·Apr 17, 2025

Here is the commented solution for this project.

Set up the project

Create a file named lb_wc.js.

$ touch lb_wc.js

Implement a command-line parser

The objective of this part is to implement a parser for command-line flags and positional arguments.

  1. Import the parseArgs() function exported by the core Node.js node:util module

    lb_wc.js
    const { parseArgs } = require('node:util');
  2. Use the parseArgs() function to define the -l (short for --lines), -w (short for --words), and -c (short for --bytes) boolean command-line flags and allow for positional arguments.

    lb_wc.js
    const { parseArgs } = require('node:util');