2023-04-13
5194
#node#typescript
Stanley Ulili
139072
Apr 13, 2023 â‹… 18 min read

Building a TypeScript CLI with Node.js and Commander

Stanley Ulili I'm a freelance web developer and researcher from Malawi. I love learning new things, and writing helps me understand and solidify concepts. I hope by sharing my experience, others can learn something from them.

Recent posts:

Comparing Mutative Vs Immer Vs Reducers For Data Handling In React

Comparing React state tools: Mutative vs. Immer vs. reducers

Mutative processes data with better performance than both Immer and native reducers. Let’s compare these data handling options in React.

Rashedul Alam
Apr 26, 2024 â‹… 7 min read
Radix Ui Adoption Guide Overview Examples And Alternatives

Radix UI adoption guide: Overview, examples, and alternatives

Radix UI is quickly rising in popularity and has become an excellent go-to solution for building modern design systems and websites.

Nefe Emadamerho-Atori
Apr 25, 2024 â‹… 11 min read
Understanding The Css Revert Layer Keyword, Part Of Css Cascade Layers

Understanding the CSS revert-layer keyword

In this article, we’ll explore CSS cascade layers — and, specifically, the revert-layer keyword — to help you refine your styling strategy.

Chimezie Innocent
Apr 24, 2024 â‹… 6 min read
Exploring Nushell, A Rust Powered, Cross Platform Shell

Exploring Nushell, a Rust-powered, cross-platform shell

Nushell is a modern, performant, extensible shell built with Rust. Explore its pros, cons, and how to install and get started with it.

Oduah Chigozie
Apr 23, 2024 â‹… 6 min read
View all posts

7 Replies to "Building a TypeScript CLI with Node.js and Commander"

  1. I follow the article and finish it successfuly,but i gt one question. how could we run dirmanager command in any path of system and get the correct result.e.g, i run dirmanager -l command in C, but get the list of files stored beside index.js file which is my executble file.
    thanks for your response in advance.

    1. Thre code uses __dirname in multiple places — it’s the directory in which the script lies. Replace __dirname everywhere with “process.cwd()” to get the behavior you want (which is the correct behavior IMO!)

  2. You can provide the directory path of your choosing after the -l option:

    dirmanager -l C:\Users\(User_Name)\Documents

  3. Great tutorial! You might want to call out the shebang/hashbang requirement though as it is in the example but if a developer isn’t aware the global script won’t execute correctly.

  4. I’m a student and I followed the guide perfectly, but when I push the workflow it gives me an error. Would you be so kind as to explain your answer?

Leave a Reply