DEV Community

Cover image for Build a CLI with Node.js

Build a CLI with Node.js

Rushan Khan on January 18, 2021

Command-line utilities are the most basic and beautiful apps ever created, the apps that started it all. We use command-line utilities every day, ...
Collapse
 
crimsonmed profile image
Médéric Burlet

You should look into oclif it comes with a whole cli management api

Collapse
 
rushankhan1 profile image
Rushan Khan • Edited

Thanks for informing, I'll check it out.

Collapse
 
hedirose profile image
Hedi O

Cool, very good quick intro to yargs.
For the help function you couldve just used yarg.showHelp()
They already made that.

Collapse
 
rushankhan1 profile image
Rushan Khan • Edited

Thanks for reading! I did use the showHelp() function but that only showed the usage instructions when I used the --help flag, I wanted to show the usage too when no argument was passed hence I also made a custom usage template to print it out in the absence of an argument.

Collapse
 
uguremirmustafa profile image
uguremirmustafa

Thanks for the post! I would like to use .env variables in my cli app but when I npm link it, it cannot reach my .env files from any other directories. Do you have any advice solving this problem?

Collapse
 
rushankhan1 profile image
Rushan Khan • Edited

Thanks for reading!
Have you tried setting the exact path of your .env file in the .env config as so:

require('dotenv').config({ path: '/absolute/path/to/your/.env/file' })
Enter fullscreen mode Exit fullscreen mode
Collapse
 
dhren2019 profile image
Dhren

Wow nice post 😲

Collapse
 
rushankhan1 profile image
Rushan Khan

Thank you!

Collapse
 
mdbetancourt profile image
Michel Betancourt

hello!, i made a lib to create cli github.com/mdbetancourt/soly

Collapse
 
jupiteris profile image
Jupiter Programmer

Good Post!!!

Collapse
 
rushankhan1 profile image
Rushan Khan

Thanks for reading!

Collapse
 
cmlandaeta profile image
cmlandaeta

Ohhh q bueno...

Collapse
 
rushankhan1 profile image
Rushan Khan

Thanks!