Urgent.News

What's breaking now, across thousands of outlets.

Tech

You Don't Need Express to Build a Microservice (Here's the Zero-Dependency Version)

Open ten "Node.js microservices" tutorials and nine start the exact same way: install Express, install an HTTP client, write a docker-compose.yml, stand up a message broker. By the time application code shows up, you've installed six things and still don't know if microservices were even the right call. Node ships with everything two communicating services actually need. node:http is the server.…

Do not assume you need Express to create a Node.js microservice, as this article demonstrates. Contrary to the typical tutorials, which start by installing Express, an HTTP client, a docker-compose.yml file, and a message broker, the author shows that Node.js already includes everything required for two communicating services. The server is the `node:http` module, the client is the global `fetch` function, the runner is `node:test`, and the reloader is `--watch`.

All of this can be achieved without installing additional dependencies or creating separate folders for each service.

The author built two real services, a user service and an order service, using this zero-dependency approach. The order service checks if a user exists before creating an order for them, communicating across the boundary with a simple `fetch`. The author encountered the actual failure modes of distributed systems and not just the theoretical ones.

When an unhandled rejection occurs inside your request handler, it can bring down both the calling and the called services. A single try/catch block is enough to demonstrate this lesson.

However, the bigger issue is not technical but rather conceptual. Splitting a codebase into two folders may seem like a step towards microservices, but it only adds operational cost without providing any actual benefit. Both services still connect to the same database schema, offering no independent deployability. The author walks through building both services, testing them with `node:test`, and observing the failure in real-time.

You can view the process here: https://devencyclopedia.com/blog/nodejs-microservices-without-express. If you have been reaching for Express and Docker by default before writing any logic, this article offers a valuable first step.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Choosing free on-prem git server - Gitea is the winner!

Wanting to move your projects away from open cloud git providers and thinking of self-hosting internal git server locally?

  • Gitea is lightweight self-hosted Git server alternative to cloud providers.
  • Dockerized installation includes PostgreSQL database container.
  • HTTPS setup requires modifying app.ini and using reverse proxy.

More from Saturday 12 September →