DEV Community

Cover image for I got tired of writing Express.js boilerplate, so I built a CLI to do it for me. 🪓
Soultane
Soultane

Posted on

I got tired of writing Express.js boilerplate, so I built a CLI to do it for me. 🪓

Every time I started a new Node.js backend project, the first hour was exactly the same.

Run npm init. Install Express, Mongoose, Cors, Dotenv. Create the src folder. Manually set up the database connection. Write the same JWT authentication controllers. Wire up the error handlers.

It is incredibly repetitive, and as a developer, if I have to do something more than three times, I want to automate it.

So, I built ForgeX — an interactive CLI engine that scaffolds production-ready, highly modular Express.js architectures in seconds.

📦 See it in action
You can try it right now in your terminal without installing anything permanently:

Bash
npx forgex-generator@latest init
(Or install it globally with npm install -g forgex-generator and just type forgex init)

⚡ What does it actually do?
When you run the command, ForgeX asks you a series of interactive questions about your tech stack and then dynamically compiles a custom backend for you.

Out of the box, it generates:

Database & ORM setup: Choose between PostgreSQL, MySQL, or MongoDB, paired with Prisma, Sequelize, Mongoose, or native drivers.

Instant Authentication: Automatically scaffolds user models, JWT generation, and auth middlewares.

Full CRUD Generation: Need a Product resource? ForgeX creates the Controller, Service, Model, Validation schemas, and Route files, then automatically injects the route into your central router using AST parsing.

Security & Quality: Configures Helmet, global error handling, asynchronous catch blocks, and optional ESLint/Prettier setups.

🛠️ How I built it under the hood
I wanted this to be more than just a template cloner. I wanted a true generation engine.

Inquirer.js & Chalk: To build the interactive, color-coded terminal interface so developers can select exactly what they need.

EJS (Embedded JavaScript templates): Instead of copying static files, the CLI uses EJS to dynamically render files based on your choices. If you choose Prisma, the db.js file compiles with Prisma syntax. If you choose Mongoose, it compiles the Mongoose connection logic.

AST (Abstract Syntax Tree) Parsing: This was the hardest but most rewarding part. When you generate a new resource, ForgeX literally reads your main routes.js file as a syntax tree, finds the exact correct line of code, and safely injects the new route import without breaking your existing code.

🤝 I need your feedback (Roast my code!)
I am currently finishing up my software engineering diploma, and I built this to speed up my own workflow. But I want to make sure the architectures ForgeX generates hold up to real-world, industry standards.

If you are an experienced backend developer, I would love for you to try it out and tell me what I did wrong.

Are the folder structures scalable?

Is the Prisma integration optimal?

How can I improve the error handling?

Drop your feedback in the comments, or open an issue on GitHub!

📖 Read the Docs: https://forge-x-generator.vercel.app/
💻 Check out the Source Code: https://github.com/SoultaneRaqi/forgex-generator-cli

If you find it useful, a ⭐️ on GitHub would mean the world to me!

Top comments (0)