Skip to main content
nestrs ships a CLI called 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.
1

Install the CLI

Install nestrs-scaffold from crates.io. The binary is named nestrs.
Verify the installation:
You should see output like:
cargo install compiles the CLI from source. This takes a minute the first time. Subsequent updates are faster because Cargo caches dependencies.
2

Create a new project

Run nestrs new with your project name:
The CLI creates the following structure:
The generated Cargo.toml includes nestrs, tokio, and serde as dependencies:
Use nestrs new my-api --strict to add #![deny(unsafe_code)] to the generated src/main.rs. Use --no-git to skip initialising a git repository.
3

Explore the generated application

Open src/main.rs. The CLI generates a complete working application with a module, a controller, an injectable service, and a bootstrapped NestFactory:
Notice the three building blocks:
  • AppService — marked #[injectable], registered in providers. This is where your business logic lives.
  • AppController — marked #[controller(prefix = "/")], registered in controllers. Route handlers go in its impl block.
  • AppModule — marked #[module(...)], wires the controller and provider together and is handed to NestFactory.
4

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.
5

Make your first HTTP request

The generated app mounts routes under the api global prefix. Send a request to the root handler:
You should receive:
The scaffolded app also provides two built-in endpoints:

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-id header via .use_request_id().
  • Structured tracing — request/response logging via .use_request_tracing(...).
  • Prometheus metrics — exported at /metrics via .enable_metrics(...).
  • Health check — responds at /health via .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:
Source lives at 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.