DEV Community

Cover image for Stop Writing Boilerplate! Build Node.js APIs in Seconds [2024 Guide]
Ivan Ivanov
Ivan Ivanov

Posted on

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!

Top comments (4)

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

Hi Ivan! Which are the options to choose from on these CLI questions?

I assume it scaffolds everything depending on your choices so your effort as a user is lessened to the maximum extent?

Collapse
 
ivanivanovv profile image
Ivan Ivanov

Hey Joel, the options you pick are completely up to you, we have added the most popular choices so devs can build their APIs based on their development preferences, we don't want you to follow "our way of building APIs".

The CLI will set up the project and all API Modules based on the selected options. For example, if you select pnpm, zod and PostgreSQL your project dependencies will be installed with pnpm, all endpoint schema validations will use zod and the DB integration will be with PostgreSQL with the SQL queries required to make it work.

We will add a default flag pretty soon so you can skip most of the questions and use the default options based on what we think are the latest best practices and tools :)

Let me know if you try it out and what else we can improve :) You can also contribute directly to the GitHub repo!

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

Thanks!
I've already added it to the queue for testing 😁

One last question, does it also provide some framework choice such Express, Fastify and so on?
Maybe runtime choice? E.g. Node or Deno

Will take a look at the repo ASAP, thank you!

Thread Thread
 
ivanivanovv profile image
Ivan Ivanov

Currently, we only support Node.js + Express.js, however, we have plans to make it work for pretty much any JS framework and runtime.

That should be easy to get working with pretty much anything once the core logic is developed for each API module.

Also a note, the modules are built with TS, again, in the near future we plan to give devs the choice between JS or TS.

We want to get some feedback from developers first so we know what to focus on next!