NestJS




A progressive Node.js framework for building efficient and scalable server-side applications on top of TypeScript & JavaScript (ES6 / ES7 / ES8) heavily inspired by Angular

底层用 express

设计理念
这个后端框架受 Angular 启发 , 所以业务代码看起来和 Angular一样
完全基于typescript的web框架,完全oop风格

底层是 express,如果是koa,或者fastify的话,或许会比较火


2018-01-05


官网
https://nestjs.com/


Nest官方叫我们去看Angular 的依赖注入的文档
Nest is built around the strong design pattern commonly known as Dependency Injection. There's a great article about this concept in the official Angular documentation.


根据类型注入 , 不能根据 key

公司




已经很好用了 , 但是不确定是否这么强大 : 高级的功能

官方提供的ORM
分布式微服务

官方有提供 :
命令行工具


示例代码
https://github.com/nestjs/nest.git
E:\NestJS\nest\examples

框架源码
https://github.com/nestjs/nest.git



components 注解相当于 Spring 的 @Service

最后在模块里配置一下 , 相当于Spring 的 xml 配置

import { Module } from '@nestjs/common';
import { CatsController } from './cats/cats.controller';
import { CatsService } from './cats/cats.service'; @Module({
controllers: [CatsController],
components: [CatsService],
})
export class ApplicationModule {}
9
 
1
import { Module } from '@nestjs/common';
2
import { CatsController } from './cats/cats.controller';
3
import { CatsService } from './cats/cats.service';
4

5
@Module({
6
    controllers: [CatsController],
7
    components: [CatsService],
8
})
9
export class ApplicationModule {}



实践

npm start 或者 npm run start
默认在 3000 端口
npm start

> nest-typescript-starter@1.0.0 start E:\NestJS\nest\examples\01-cats-app
> node index.js [Nest] 12736 - 2018-1-5 09:11:29 [NestFactory] Starting Nest application...
[Nest] 12736 - 2018-1-5 09:11:29 [InstanceLoader] ApplicationModule dependencies initialized +7ms
[Nest] 12736 - 2018-1-5 09:11:29 [InstanceLoader] CatsModule dependencies initialized +2ms
[Nest] 12736 - 2018-1-5 09:11:29 [RoutesResolver] CatsController {/cats}: +29ms
[Nest] 12736 - 2018-1-5 09:11:29 [RouterExplorer] Mapped {/, POST} route +1ms
[Nest] 12736 - 2018-1-5 09:11:29 [RouterExplorer] Mapped {/, GET} route +0ms
[Nest] 12736 - 2018-1-5 09:11:29 [RouterExplorer] Mapped {/:id, GET} route +1ms
[Nest] 12736 - 2018-1-5 09:11:29 [NestApplication] Nest application successfully started +1ms
x
 
1
npm start
2

3
> nest-typescript-starter@1.0.0 start E:\NestJS\nest\examples\01-cats-app
4
> node index.js
5

6
[Nest] 12736   - 2018-1-5 09:11:29   [NestFactory] Starting Nest application...
7
[Nest] 12736   - 2018-1-5 09:11:29   [InstanceLoader] ApplicationModule dependencies initialized +7ms
8
[Nest] 12736   - 2018-1-5 09:11:29   [InstanceLoader] CatsModule dependencies initialized +2ms
9
[Nest] 12736   - 2018-1-5 09:11:29   [RoutesResolver] CatsController {/cats}: +29ms
10
[Nest] 12736   - 2018-1-5 09:11:29   [RouterExplorer] Mapped {/, POST} route +1ms
11
[Nest] 12736   - 2018-1-5 09:11:29   [RouterExplorer] Mapped {/, GET} route +0ms
12
[Nest] 12736   - 2018-1-5 09:11:29   [RouterExplorer] Mapped {/:id, GET} route +1ms
13
[Nest] 12736   - 2018-1-5 09:11:29   [NestApplication] Nest application successfully started +1ms

有请求路由的信息 , 比如
/cats



暂时没数据

要发POST请求创建数据 , 角色是 admin , 不然不能添加数据
@UseGuards(RolesGuard)

然后get再获取一次

Guards are executed after every middleware, but before pipes.

为什么要用 Guards ? 之前已经用了 middleware






项目加载顺序
从左到右




最新文章

  1. flash小游戏在Kongregate上线——BasketBall Master(篮球大师)
  2. iOS: setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key name.
  3. 【Alpha版本】 第八天 11.16
  4. vertical-align两种应用场合
  5. PHP与jquery前后台交互的小程序
  6. [SSH 3]以网上商城项目浅谈spring配置
  7. Eclipse设置选中高亮显示(包含debug)
  8. Blending(融合)
  9. (转)TeamCity配置笔记
  10. 译文:javascript function中的this
  11. 处理部分WordPress核心代码或功能,让你的网站更快
  12. Spring面试笔记
  13. ztree树应用
  14. 【RL-TCPnet网络教程】第24章 RL-TCPnet之网络控制报文协议ICMP
  15. Android的Activity组件
  16. windows提交代码到git仓库
  17. EF code first Mysql 更换主键类型
  18. PHP性能监测的工具介绍 - XHProf -参考自https://jingyan.baidu.com/article/7082dc1c173359e40a89bd95.html
  19. postmessage/cors跨域postMessage、xhr2和xmldomain
  20. Anaconda安装及配合pycharm使用

热门文章

  1. How to add a date range picker to filter for dates on a GridView for Yii2 - See more at: http://www.2amigos.us/blog/how-to-add-a-date-range-picker-to-filter-for-dates-on-a-gridview-for-yii2#sthash.pf7
  2. Discuz!X2截屏控件手动安装教程-Xproer.ScreenCapture
  3. .NET基础 (05)内存管理和垃圾回收
  4. 20169214 2016-2017-2 《网络攻防实践》第十一周实验 SQL注入
  5. python中用ElementTree.iterparse()读取xml文件中的多层节点
  6. js防windos锁屏功能实现
  7. [LeetCode 题解]:Best Time to Buy and Sell Stock
  8. depth深度
  9. day05.1-文件处理
  10. 【OCP-12c】CUUG最新考试原题整理及答案(071-9)