DEV Community

Cover image for 🚀 A Tiny Developer Tool I Built for My Node.js Workflow
ABDULLAH BIN MUGHIRA
ABDULLAH BIN MUGHIRA

Posted on AI-assisted

🚀 A Tiny Developer Tool I Built for My Node.js Workflow

While working on Node.js + Express projects, I noticed I was repeatedly generating JWT secrets for my .env files.

Usually, I would either:

→ Search for an online secret generator
→ Run a long Node.js command manually
→ Copy the generated value
→ Paste it into .env

It's not difficult, but when you're doing it repeatedly, why not automate it?

So I created my own tiny Windows command called jwt.

Now I can simply type:

jwt
Enter fullscreen mode Exit fullscreen mode

and get a secure random secret instantly.

Even better:

jwt 64
Enter fullscreen mode Exit fullscreen mode

generates a 64-byte random secret instead of the default 32-byte secret.

🛠️ How I built it

I used Node.js' built-in crypto module, so there was no additional npm package involved.

First, I created a folder:

C:\Users\YOUR_USERNAME\bin
Enter fullscreen mode Exit fullscreen mode

Then I created:

jwt.cmd
Enter fullscreen mode Exit fullscreen mode

inside that folder.

The file contains:

@echo off
if "%~1"=="" (
    set "bytes=32"
) else (
    set "bytes=%~1"
)

node -e "console.log(require('crypto').randomBytes(%bytes%).toString('hex'))"
Enter fullscreen mode Exit fullscreen mode

🔍 What does it do?

%~1 represents the first argument passed to the command.

So:

jwt
Enter fullscreen mode Exit fullscreen mode

means no argument was provided, therefore:

bytes = 32
Enter fullscreen mode Exit fullscreen mode

While:

jwt 64
Enter fullscreen mode Exit fullscreen mode

sets:

bytes = 64
Enter fullscreen mode Exit fullscreen mode

Then Node.js runs:

crypto.randomBytes(bytes)
Enter fullscreen mode Exit fullscreen mode

which generates cryptographically secure random bytes.

Finally:

.toString('hex')
Enter fullscreen mode Exit fullscreen mode

converts them into a hexadecimal string.

For example:

jwt
Enter fullscreen mode Exit fullscreen mode

32 bytes → 64 hexadecimal characters
64 bytes → 128 hexadecimal characters

🌐 Making the command available everywhere

The final step was adding my bin folder to the Windows User PATH.

I went to:

Windows Search → Environment Variables → Edit the system environment variables → Environment Variables

Under User variables, I selected:

Path → Edit → New
Enter fullscreen mode Exit fullscreen mode

and added:

C:\Users\YOUR_USERNAME\bin
Enter fullscreen mode Exit fullscreen mode

After restarting the terminal, Windows could find jwt.cmd from any directory.

Now I can open CMD, PowerShell, or the VS Code terminal and simply run:

jwt
Enter fullscreen mode Exit fullscreen mode

or:

jwt 64
Enter fullscreen mode Exit fullscreen mode

💡 Why I like this

It's a very small automation, but it taught me something useful about Windows PATH, .cmd files, command-line arguments, and Node's crypto module.

More importantly, it removed a repetitive step from my development workflow.

Sometimes developer productivity isn't about building a huge tool.

Sometimes it's just:

"I do this repeatedly → let's automate it."

Top comments (0)