Count lines, words, and characters in a text file.
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.argv to read the file path from the terminal.
node:fs/promises to read the file contents.
node:path to print a clean file name.
Join the Community
roadmap.sh is the most starred project on GitHub and is visited by hundreds of thousands of developers every month.
Roadmaps Best Practices Guides Videos FAQs YouTube
roadmap.sh by @kamrify @kamrify
Community created roadmaps, best practices, projects, articles, resources and journeys to help you choose your path and grow in your career.
Login or Signup
You must be logged in to perform this action.