-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nestjs #162
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NestJS 是一个用于构建高效、可扩展的 Node.js 服务器端应用程序的框架。它使用 TypeScript 编写(也支持 JavaScript),并结合了 OOP(面向对象编程),FP(函数式编程)和 FRP(函数响应式编程)的元素。
将从基本概念和关键组件开始讲解,然后引导你创建一个简单的 CRUD 项目。让我们开始吧!
安装和创建项目: 首先,确保你的计算机上已经安装了 Node.js 和 npm。然后在命令行中运行以下命令安装 Nest CLI:
接下来,使用 Nest CLI 创建一个新项目:
然后进入项目目录:
cd my-nestjs-project
关键概念和组件: NestJS 由一系列组件组成,这有助于开发者在应用程序中保持组织和模块化。主要组件包括:
创建一个简单的 CRUD 项目: 为了让你更好地了解 NestJS 的工作原理,我们将创建一个简单的 CRUD(创建、读取、更新、删除)项目。这里我们假设你要操作一个名为“Item”的实体。
2.接下来,打开 items.controller.ts 文件,添加以下代码:
现在,打开 items.service.ts 文件,添加以下实现代码:
紧接着,在 items 文件夹中创建两个新文件:create-item.dto.ts 和 update-item.dto.ts,用于定义创建和更新 item 的数据传输对象(DTO):
create-item.dto.ts 文件内容如下:
update-item.dto.ts 文件内容如下:
现在,运行项目:
你将获得一个基本的 CRUD 项目,可以执行以下操作:
这就是一个简单的 NestJS CRUD 项目。当然,实际项目中你可能还需要考虑如何连接数据库、实现用户鉴权等功能。我建议你查阅 NestJS 官方文档(https://docs.nestjs.com/)
The text was updated successfully, but these errors were encountered: