Skip to main content
nestrs is available on crates.io. Add it to your project by editing Cargo.toml directly, or use cargo add. This page covers the minimum required setup, the tokio runtime configuration, and the full table of optional feature flags.

Minimum supported Rust version

nestrs requires Rust 1.88 or later. Run rustup update stable to ensure your toolchain is current before adding the dependency.

Adding nestrs to your project

nestrs depends on tokio for its async runtime. You must enable the macros and rt-multi-thread features on tokio alongside nestrs:
[dependencies]
nestrs = "0.3.8"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
Your main function must be annotated with #[tokio::main]:
use nestrs::prelude::*;

#[tokio::main]
async fn main() {
    NestFactory::create::<AppModule>().listen_graceful(3000).await;
}
If you use DTO validation with #[dto] and its field-level macros, also add serde and validator:
serde = { version = "1", features = ["derive"] }
validator = { version = "0.20", features = ["derive"] }

Optional feature flags

nestrs has a default = [] feature set — nothing optional is enabled unless you ask for it. Enable features by adding them to the features list on the nestrs dependency:
nestrs = { version = "0.3.8", features = ["openapi", "cache-redis"] }
The table below lists every available feature flag and what it adds to your project.

Transport and protocol features

FeatureWhat it enables
wsWebSocket gateway helpers via nestrs-ws
graphqlasync-graphql router integration via nestrs-graphql
openapiOpenAPI spec generation and Swagger UI via nestrs-openapi

Microservices features

FeatureWhat it enables
microservicesBase microservices support: transport traits, event bus (nestrs-microservices + nestrs-events)
microservices-natsNATS transport (implies microservices, adds async-nats)
microservices-redisRedis pub/sub transport (implies microservices, adds redis)
microservices-kafkaKafka transport (implies microservices)
microservices-mqttMQTT transport (implies microservices)
microservices-rabbitmqRabbitMQ transport (implies microservices)
microservices-grpcgRPC-style transport (implies microservices)
All microservices-* features automatically enable the base microservices feature. You do not need to list both.

Data and storage features

FeatureWhat it enables
cache-redisRedis-backed caching via the redis crate
database-sqlxSQLx integration for Postgres, SQLite, and other databases
mongoMongoDB integration via the mongodb crate

HTTP and request handling features

FeatureWhat it enables
cookiesCookie extraction and setting via tower-cookies
sessionSession middleware via tower-sessions (implies cookies)
csrfCSRF protection (implies cookies, adds subtle)
http-clientHTTP client via reqwest (JSON support, rustls TLS)
filesStatic file serving via tokio-util
mvcServer-side template rendering via minijinja

Infrastructure features

FeatureWhat it enables
scheduleCron-style task scheduling via tokio-cron-scheduler and linkme
queuesIn-process job queues via linkme
otelOpenTelemetry tracing export (OTLP/gRPC) via opentelemetry, opentelemetry_sdk, opentelemetry-otlp, and tracing-opentelemetry

Common configuration examples

[dependencies]
nestrs = "0.3.8"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

Release profile recommendations

The CLI-generated Cargo.toml includes a tuned release profile. Add this to your own Cargo.toml for optimised production builds:
[profile.release]
opt-level = 3
lto = "thin"
codegen-units = 1
strip = "symbols"
panic = "abort"
panic = "abort" skips stack unwinding on panic. This reduces binary size and can improve performance, but means destructors do not run on panic. Evaluate this setting against your application’s requirements before enabling it.

Environment variables

nestrs reads a .env file at startup via dotenvy. Create a .env file in your project root to configure the runtime:
PORT=3000
NESTRS_ENV=development
RUST_LOG=info
DATABASE_URL=file:./dev.db
Set NESTRS_ENV=production to activate production error sanitisation when you call .enable_production_errors_from_env() in main.

Next steps

Quickstart

Build and run your first nestrs project from scratch using the CLI.

Core concepts

Learn how modules, controllers, and providers compose into a structured application.