Seyyed Ali Mohammadiyeh (Max Base) Node.js Global Summit 25 - May 20, 2025
Seyyed Ali Mohammadiyeh (Max Base) Open-source Maintainer, GitHub Senior Software Engineer CTO, asrez maxbasecode@gmail.com
Explore how Bun and TypeScript enable the creation of a high-performance, real-time gateway that routes incoming HTTP requests to the appropriate microservices.
Real-world architecture & benchmarks Code examples Lessons from production
$ bun init ✓ Select a project template: Blank + .gitignore + index.ts + tsconfig.json (for editor autocomplete) To get started, run: bun run index.ts
// index.ts console.log("Hello via Bun!");
$ bun run index.ts Hello via Bun!
Native HTTP server (no need for Express or external frameworks) Written in TypeScript Built-in routing based on URL, headers, or tokens Blazing fast Zero dependencies
Downsides: Type checking and runtime validation in TypeScript is still maturing. Limited ecosystem maturity compared to Node.js
const server = Bun.serve({ port: 9999, fetch(req) { return new Response("Not Found", { status: 404 }); }, });
fetch()
req
const server = Bun.serve({ port: 9999, fetch(req) { const url = new URL(req.url); console.log(url); return new Response("Not Found", { status: 404 }); }, });
Example req (request) object:
Request { method: "GET", url: "http://localhost:9999/", headers: Headers { "host": "localhost:9999", "user-agent": "...", ... } }
Key values to use:
req.method
req.url
req.headers
Output of new URL(req.url):
new URL(req.url)
URL { href: "http://localhost:9999/favicon.ico", origin: "http://localhost:9999", pathname: "/favicon.ico", searchParams: URLSearchParams {} }
Imagine we are working on a large-scale project with over 800 RESTful API routes.
From an architectural perspective, we can split the entire platform into 20 sub-projects.
Each of these 20 sub-projects runs independently and serves on a different HTTP port.
Now, we need a central gateway — a program that initially receives all incoming requests from end users. It should analyze each request to determine which sub-project or microservice it belongs to and then forward the request accordingly.
The gateway must not only forward the request to the appropriate sub-project but also handle the response by forwarding it back to the user.
{ "host": "0.0.0.0", "port": 9999, "services": [ { "prefix": "/user/", "host": "localhost", "port": 8888 }, { "path": "/my/login/", "method": "POST", "host": "localhost", "port": 6666 }, ... ] }
Create a new Bun project:
bun init
Thank you!
github.com/basemax maxbasecode@gmail.com