DEV Community

Cover image for Automate your workflow using NodeJS CLI programs
Karan Sharma
Karan Sharma

Posted on

3 3

Automate your workflow using NodeJS CLI programs

Automating your workflow shifts the focus from doing the unnecessary and repetitive task to a more important thing and prevents us from procrastinating. As a JS developer, I always want something that prevents fiddling for things around BASH while writing my workflows and gives me confidence and control over the task in hand.

Steps for Writing a simple CLI program

In this, I will take one trivial task of opening the projects or run specific commands like running tests over them.

1) Always begin your scripts with
Start of Script
This is to specify that it is a node script and to be treated as CLI program.

2) Helpers for making it more easy and fun
This list includes
helper programs

3) Breakdown your requirements in form of JSON object
Writing your requirements in JSON makes it easy to extend and review changes later on.
Config

4) Writing the workflow
Don't over complicate things and just write simple reusable functions that can be used across all your CLI tools.

main flow

5) Making it installable and accessible from anywhere.
Make an entry in package.json of your project specifying the initial point of the script.

trick
and then running npm link in the directory will install it like any other CLI program in /usr/bin.
This little trick makes it accessible when used from anywhere like in the above example workflow can be invoked from CLI globally.

Alt Text

You can find the complete code for this tool at my github repo.

GitHub logo curiouskaran / projectOpener

Open a project that has alias listed in a json

Thanks for reading! Please let me know in the comments for any thoughts and improvements.

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay