Stop Writing Boilerplate! Build Node.js APIs in Seconds [2024 Guide]

ivanivanovv

Ivan Ivanov

Posted on November 18, 2024

Stop Writing Boilerplate! Build Node.js APIs in Seconds [2024 Guide]

Have you ever set up a Node.js backend and felt like you were reinventing the wheel? Hours spent configuring TypeScript, setting up routing, writing boilerplate code - it’s the same process every time.

As someone who has been building Node.js backend services for the last five years, I know this struggle all too well. That’s why I decided to create Vratix, an open-source library of reusable API modules you can copy and paste into your codebase. It’s open source, extensible, and developer-friendly, making it an ideal choice for any project.

Think of it as shadcn/ui but for backend APIs. Vratix provides everything you need to get up and running in seconds:

  • Controllers and routes
  • Endpoint validation
  • Database integration
  • Docker + NGINX configurations for deployment

It’s fully typed with TypeScript and includes tests for all business logic using Vitest.

So how do you exactly get a fully working API in seconds? Vratix comes with a CLI that makes starting a new project or adding API modules super simple. To get started just run:

npx vratix init
Enter fullscreen mode Exit fullscreen mode

See the full docs here: vratix.com

Quick guide

The CLI will prompt you with a few questions to configure your project and create ./config/modules.json:

Select your package manager: 
› pnpm

What database are you going to use: 
› PostgreSQL

Select your schema validator: 
› zod

Should we set up Docker containers for this service (docker-compose.yaml): 
› no / yes 

Should we configure a web proxy for this project (NGINX): 
› no / yes
Enter fullscreen mode Exit fullscreen mode

During setup, select any initial API Modules you’d like to install as part of the project template:

☐ Auth 
☐ Stripe Subscriptions
☐ S3 File Upload
☐ Emails (Postmark)
...
☐ None
Enter fullscreen mode Exit fullscreen mode

If you choose "None," you can always add modules later with

npx vratix add <module>
Enter fullscreen mode Exit fullscreen mode

Customize the paths for main module folders if needed:

@components -> /src/components
@routes -> /src/routes
@middleware -> /src/middleware
@utils -> /src/utils
Enter fullscreen mode Exit fullscreen mode

Note: Any folder overrides will still be located within /src.

Ready To Go

Once setup is complete, to start your service run:

npm run dev
Enter fullscreen mode Exit fullscreen mode

Give it a spin and let me know your feedback on Discord or contribute on GitHub!

💖 💪 🙅 🚩
ivanivanovv
Ivan Ivanov

Posted on November 18, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related