Node.js又一框架:Nest.js(一)

598 阅读1分钟

简介

Nest.js:用于构建高效且可伸缩的服务端应用程序的渐进式 Node.js 框架。

  1. 完美支持 TypeScript
  2. 面向 AOP 编程;
  3. 支持 Typeorm
  4. 高并发,异步非阻塞 IO
  5. Node.js 版的 Spring
  6. 构建微服务应用。

在底层,Nest 使用强大的 HTTP Server 框架,如:Express(默认)和 Fastify

前置

Node.js(>= 10.13.0)

node -v
# v12.14.1
npm -v
# 6.13.4

安装

  1. 使用 Nest CLI 构建项目
# npm
npm i -g @nestjs/cli
# yarn
yarn global add @nestjs/cli

nest new project-nest
  1. 使用 Git 克隆项目
# TypeScript
git clone https://github.com/nestjs/typescript-starter.git project-nest
# JavaScript
git clone https://github.com/nestjs/javascript-starter.git project-nest

cd project-nest
npm install

# npm
npm run start
# yarn
yarn run start
  1. 手动创建
# 通过使用 npm 或 yarn 安装核心和支持文件,从头开始手动创建项目,自主负责创建项目样板文件。
npm i --save @nestjs/core @nestjs/common rxjs reflect-metadata

运行

cd project-nest

# npm
npm run start
# yarn
yarn run start

访问

http://localhost:3000/

image.png