nest README

项目的 README,来自 github.com/nestjs/nest。合并为一个 markdown 文件:README.md。

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications, from a small API in one file to enterprise-grade systems.

NPM Version Package License NPM Downloads CircleCI Discord Backers on Open Collective Sponsors on Open Collective Support us

Description

Nest is a TypeScript framework for building backends on Node.js, from a small API in one file to an enterprise-grade system with many teams. It gives an application modules, dependency injection, and one place each for validation, authentication and error handling, so a project keeps its shape as it grows.

It runs on Express, Fastify or Node's own node:http, and its first-party packages cover most of what a backend needs, so you can start small and add them as you go.

On node:http, through the NodeAdapter, Nest handles about 3% fewer requests per second than plain Fastify and about 50% more than Express (benchmark).

Quick start

npx @nestjs/cli new my-api
cd my-api
npm run start:dev

A coding agent or a script can create the project in the current folder with npx @nestjs/cli new . --skip-git --package-manager npm, which asks nothing when stdin isn't a terminal and adds an AGENTS.md for the agent to read.

Add --minimal to start from a single file. An application can be this small:

import { Controller, Get } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';

@Controller()
class AppController {
  @Get()
  hello() {
    return 'Hello, Nest!';
  }
}

const app = await NestFactory.create({ controllers: [AppController] });
await app.listen(3000);

The object passed to NestFactory.create() is the root module's metadata, so imports and providers work there too. Move it into a @Module() class when the root module needs middleware, or for nest generate to register what it creates.

Run it with npm run start:dev, like any other Nest project. The Nest CLI compiles it with the decorator metadata that constructor injection by type and ValidationPipe rely on. Tools that don't emit that metadata, such as tsx, leave injected dependencies undefined.

First-party packages

What you need Package
Language models, tools as provider methods, agents, streaming to the browser @nestjs/ai
MCP servers @nestjs/mcp
Sign-in, sessions, tokens, two-factor, API keys @nestjs/authentication
Permissions @nestjs/authorization
Email @nestjs/mail
Files, S3 included @nestjs/storage
Translations @nestjs/i18n
Databases @nestjs/typeorm, @nestjs/drizzle, @nestjs/mongoose, @nestjs/sequelize
Retries, timeouts, circuit breakers @nestjs/resilience
Idempotency keys @nestjs/idempotency
Transactional outbox @nestjs/outbox
Webhooks, sending and receiving @nestjs/webhooks
Running a job on one instance, locks @nestjs/locks
Processes that take days @nestjs/workflows
Queues and scheduled jobs @nestjs/bullmq, @nestjs/schedule
GraphQL, WebSockets, microservices GraphQL, gateways, microservices
OpenAPI @nestjs/swagger
Configuration, caching, rate limiting, health checks @nestjs/config, @nestjs/cache-manager, @nestjs/throttler, @nestjs/terminus

Moving to Nest

Using a coding agent

The whole documentation is available as markdown, with an index at docs.nestjs.com/llms.txt. Projects from nest new come with an AGENTS.md that lists the packages above, since most models were trained before they existed.

The official NestJS agent skills teach an agent the current APIs and the mistakes that still pass tests. They cover starting a project, features, authentication and authorization, data, testing and production. Add them to a project with:

npx @nestjs/skills add

This copies them into .agents/skills, which Codex and Cursor read. Add --agent claude for Claude Code, or --agent all for both. Claude Code can also install them as a plugin: claude plugin marketplace add nestjs/agent-skills, then claude plugin install nestjs@nestjs.

Philosophy

In recent years, thanks to Node.js, JavaScript has become the “lingua franca” of the web for both front-end and back-end applications, giving rise to awesome projects like Angular, React, and Vue, which improve developer productivity and enable the construction of fast, testable, and extensible frontend applications. However, on the server-side, while there are a lot of superb libraries, helpers, and tools for Node, none of them effectively solve the main problem - the architecture.

Nest aims to provide an application architecture out of the box which allows for effortless creation of highly testable, scalable, and loosely coupled and easily maintainable applications. The architecture is heavily inspired by Angular.

Getting started

Questions

For questions and support please use the official Discord channel. The issue list of this repo is exclusively for bug reports and feature requests.

Issues

Please make sure to read the Issue Reporting Checklist before opening an issue. Issues not conforming to the guidelines may be closed immediately.

Observability

NestJS Observe is the official observability platform for Nest applications. Install the @nestjs/observe SDK, pass an API key, and requests, background jobs, errors, logs, and distributed traces start streaming to a dashboard - no manual span wiring and no collector to run. Because the SDK hooks into Nest's own request lifecycle, a trace reads like a call graph of your controllers and providers instead of a bare HTTP route. Free for up to 300,000 events a month, and there is a live demo with no signup.

Consulting

With official support, you can get expert help straight from the Nest core team. We provide dedicated technical support, migration strategies, advice on best practices (and design decisions), PR reviews, and team augmentation. Read more about support here.

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support from the amazing backers. If you'd like to join them, please read more here.

Principal Sponsors

Gold Sponsors

Silver Sponsors

Sponsors

Backers

Stay in touch

License

Nest is MIT licensed.

nest (nestjs/nest)

正在搜索数据库…

77.1K ·GitHub
这是什么?Nest 是一个渐进式 Node.js 框架,用于使用 TypeScript(同时兼容纯 JavaScript)构建高效、可扩展的企业级服务器端应用。
这是一个框架,还是只是一组辅助工具库?它是一个完整的应用框架,而不是零散的工具集:它采用一套有明确约定的架构(模块、控制器、提供者),灵感来自 Angular;默认运行在 Express 之上,同时支持将 Fastify 作为即插即用的 HTTP 适配器。
怎样才能让一个 Nest 项目跑起来?官方指南 docs.nestjs.com 会讲解如何搭建并运行项目,通常借助 Nest CLI;该仓库本身使用标准的 TypeScript 项目引用命令构建,如 'build' 和 'build:dev'。
我需要 TypeScript,还是可以只用纯 JavaScript?需要 Node.js 20 或更高版本;Nest 主要使用 TypeScript 构建,但它明确保留了对纯 JavaScript 的兼容性。
和直接用 Express 相比,有什么需要注意的?Nest 在 Express/Fastify 之上增加了一层有明确约定、类似 Angular 风格的结构,包括模块、装饰器和依赖注入,这意味着前期需要学习更多的结构,而不是直接编写原始的 Express 路由。
Nest 是为谁设计的?它面向需要企业级、易维护服务端架构的后端 / Node.js 开发者,而不是一个极简的路由库。
为什么 Nest 的架构以 Angular 为蓝本?作者 Kamil Mysliwiec 构建 Nest,是为了把 Angular 的模块化、依赖注入驱动的结构引入 Node.js 后端,因为现有的 Node 库只解决了单个问题,并没有解决整体应用架构的问题。
Nest 支持构建微服务吗?支持,微服务是其核心支持的模式之一,让你可以用同样的模块/提供者模型构建分布式服务,而不只是 HTTP API。
我能为 Nest 购买付费支持吗?可以,Nest 核心团队提供官方咨询服务,包括专职技术支持、迁移策略、架构建议和 PR 审查。
Nest 会把我绑定在 Express 上吗?不会,Nest 对 HTTP 层做了抽象,因此你可以把底层服务器从 Express 换成 Fastify,同时保留相同的应用代码。
作者
nestjs
大小
484 MB
星标
77.1K
时长
9年
提交 · 90 天