File Counter
Count lines, words, and characters in a text file.
5 upvotes
10 upvotes
File Counter
You are required to build a CLI tool using Node.js that counts lines, words, and characters in a text file.
The tool should accept a file path from the terminal. If the user does not pass a file path, it should print a friendly error.
Create a file called notes.txt with this content:
Here are some example commands you can run to test your CLI:
On successful execution, the output should look like this:
If the file cannot be read, print a friendly error:
If the user does not pass a file path, print this error:
Errors should go to stderr, and the command should set a non-zero exit code.
The goal of this project is to practice reading command arguments, loading a file with Node.js, and turning file content into useful counts.
You will need these Node.js APIs:
process.argvto read the file path from the terminal.node:fs/promisesto read the file contents.node:pathto print a clean file name.
Solution
Solution:
