Solution: lb_head
Node.js·2 min read·Apr 17, 2025
Here is the commented solution for this project.
Create the script
Within the projects directory, let's create a new file named lb_head.js.
$ touch lb_head.jsHandle command-line arguments
The objective of this part is to define a code block responsible for defining and parsing the command-line flags and positional arguments of the script.
Setup a try...catch block
Let's declare a try...catch block responsible for catching and logging any error that may be thrown during the parsing phase, and immediately terminate the process with an exit code of 1 indicating that something went wrong.
lb_head.js
try { // Script logic goes here...} catch(error) { console.error(error.toString()); process.exit(1);}Define CLI flags
Let's use the parseArgs() function exported by the core node:util module to define the --help, --bytes, and --lines flags.