You are browsing as a guest. Sign up (or log in) to start making projects!

Open comments for this post

55m 47s logged

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.argv works 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, mul and div commands
  • Handles invalid commands with basic error messaging
  • Uses a command map for cleaner execution logic

Next steps:

  • Add scientific functions like sqrt, pow, and log
  • 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.

0

Comments 0

No comments yet. Be the first!