Devlog 1 — Building a CLI Calculator
What I set out to build :
A command-based CLI calculator using Node.js that can take input directly from the terminal and perform operations like addition, subtraction multiplication and division.
What I learned:
-
How
process.argvworks for handling command-line input -
Why
"5" + "3"results in"53"(strings vs numbers in JavaScript) -
How to convert inputs properly using
Number() -
The difference between calling a function and referencing it
-
How to implement a command map using
commands[cmd]()
Biggest struggle:
Understanding how to structure the command system cleanly without relying on long and messy if/else chains.
Breakthrough moment:
Realizing that I could store functions inside an object and dynamically execute them based on user input. That made the whole system feel much cleaner and scalable.
Current features:
- Supports
add,sub,mulanddivcommands - Handles invalid commands with basic error messaging
- Uses a command map for cleaner execution logic
Next steps:
- Add scientific functions like
sqrt,pow, andlog - Improve input validation
- Potentially add a history system
Reflection:
Started this knowing almost nothing about CLI tools or Node.js input handling and ended up building a working command-based system. It’s simple but it actually feels like the foundation of something bigger.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.