nestrs-scaffold (binary: nestrs) that creates a fully-wired project skeleton for you. This guide uses the CLI path. If you prefer to add nestrs to an existing Cargo project, see Installation instead.
Install the CLI
Install Verify the installation:You should see output like:
nestrs-scaffold from crates.io. The binary is named nestrs.cargo install compiles the CLI from source. This takes a minute the first time. Subsequent updates are faster because Cargo caches dependencies.Create a new project
Run The CLI creates the following structure:The generated
nestrs new with your project name:Cargo.toml includes nestrs, tokio, and serde as dependencies:Explore the generated application
Open Notice the three building blocks:
src/main.rs. The CLI generates a complete working application with a module, a controller, an injectable service, and a bootstrapped NestFactory:AppService— marked#[injectable], registered inproviders. This is where your business logic lives.AppController— marked#[controller(prefix = "/")], registered incontrollers. Route handlers go in itsimplblock.AppModule— marked#[module(...)], wires the controller and provider together and is handed toNestFactory.
Run the server
Start the development server:Cargo compiles the project and starts the server. On first run this takes longer while dependencies are downloaded and compiled. Watch for output like:The
.env file sets PORT=3000 by default, so the server binds to port 3000 unless you override it.What the scaffold gives you
Beyond the minimal app, the generated project is production-ready from the start:- Request IDs — every request gets a
x-request-idheader via.use_request_id(). - Structured tracing — request/response logging via
.use_request_tracing(...). - Prometheus metrics — exported at
/metricsvia.enable_metrics(...). - Health check — responds at
/healthvia.enable_health_check(...). - Production error sanitisation — 5xx bodies are stripped in production when
NESTRS_ENV=production. - Dockerfile — multi-stage build ready to containerise your app.
Building a richer example
The hello-app example in the repository shows a more complete application with controller versioning, DTO validation, SQLx database access, and HTTP exception helpers:examples/hello-app/src/main.rs.
Next steps
Core concepts
Understand how modules, controllers, and providers compose into a full application.
Installation and features
Add optional capabilities — WebSockets, GraphQL, OpenAPI, caching, and more — via Cargo feature flags.
DTO validation
Use
#[dto], #[IsEmail], #[Length], and other validation macros to validate request bodies automatically.CLI reference
Generate controllers, services, guards, pipes, and more with
nestrs generate.