node.js를 처음 접하는 개발자를 위한 스터디 자료입니다.
실습 위주로, 간단한 웹 페이지를 만들어 보는 것을 목표로 하며,
express를 활용하기에 앞서, node.js 기본 API만으로 GET/POST 처리 방식을 알아봅니다.
내용의 깊이가 있지는 않으며, 단지 node.js의 입문을 위한 가벼운 수준으로 내용이 구성되었습니다.
node.js를 처음 접하는 개발자를 위한 스터디 자료입니다.
실습 위주로, 간단한 웹 페이지를 만들어 보는 것을 목표로 하며,
express를 활용하기에 앞서, node.js 기본 API만으로 GET/POST 처리 방식을 알아봅니다.
내용의 깊이가 있지는 않으며, 단지 node.js의 입문을 위한 가벼운 수준으로 내용이 구성되었습니다.
Adied 2014, 봄싹 세미나에서 발표한 `Resource Handling in Spring MVC`의 발표자료입니다.
주요 내용으로 Spring MVC에서 정적 자원(css, js, etc)을 다루는 방법을 다루고 있습니다.
데모 코드 : https://github.com/arawn/resource-handling-in-springmvc
스프링군살없이세팅하기(The way to setting the Spring framework for web.)EunChul Shin
깔끔하게 스프링 프레임워크 세팅하는 것에 대한 이야기 입니다.
군살없이 프레임워크를 세팅한다는 의미와 이유, 그리고 스프링 기본 설정 및 설정들의 역할에 대해서 정리해 보았습니다.
This presentation is about Spring framework.
I want to talk about the way to setting the spring framework as tidy in this presentation.
Adied 2014, 봄싹 세미나에서 발표한 `Resource Handling in Spring MVC`의 발표자료입니다.
주요 내용으로 Spring MVC에서 정적 자원(css, js, etc)을 다루는 방법을 다루고 있습니다.
데모 코드 : https://github.com/arawn/resource-handling-in-springmvc
스프링군살없이세팅하기(The way to setting the Spring framework for web.)EunChul Shin
깔끔하게 스프링 프레임워크 세팅하는 것에 대한 이야기 입니다.
군살없이 프레임워크를 세팅한다는 의미와 이유, 그리고 스프링 기본 설정 및 설정들의 역할에 대해서 정리해 보았습니다.
This presentation is about Spring framework.
I want to talk about the way to setting the spring framework as tidy in this presentation.
갑을병정 산업구조에서 갑돌이의 잦은 요구사항 변경 통보를 받아보셨을 겁니다. 사람들에게 받은 스트레스를 풀려고 '그래! 난 개발자닌깐' 하고 자리에 앉아서 코드를 짜는데 반복적인 작업을 하다보면 ‘내가 이걸 왜 하고 있나’ 라는 생각까지 들기도 합니다.
안드로이드 작업을 하다보면 다음과 같은 반복적인 작업을 하는 것을 느꼈을 겁니다.
반복적인 보일러(Boiler)코드를 줄일 수 있는 오픈소스를 소개하고자 합니다.
2. 시작하기 전에,
여기서 다루지 않는 것들
nodejs
typescript
express
여기서 다루는 것들
nestjs
nestjs 설정
3. 목차
기초
1. NestJS는?
2. 주요 특징
3. NestJS CLI 설치
4. 프로젝트 생성
5. HelloWorld
활용
1. OAS 설정
2. Validation 설정
3. Configuration 설정
4. Logger 설정
5. Session 설정
6. Helmet & cors 설정
7. HttpMoudle 설정
13. 3. Configuration-설정
필수 모듈 설치
app.module.ts – Global 설정으로 처리
$ npm I --save @nestjs/config
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { AppController } from './app.controller
';
import { AppService } from './app.service';
@Module({
imports: [ConfigModule.forRoot()],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
14. 3. Configuration – 사용 예
import { Body, Controller, Get, Post } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { AppService } from './app.service';
import { UserDto } from './dto/User.dto';
@Controller()
export class AppController {
constructor(private readonly appService: AppService, private configService: ConfigService) { }
@Get()
getHello(): string {
return this.appService.getHello();
}
@Post('valid')
testValid(@Body() userDto: UserDto) {
// get an environment variable
const dbUser = this.configService.get<string>('DATABASE_USER');
// get a custom configuration value
const dbHost = this.configService.get<string>('DATABASE_PASSWORD');
return "pass valid! : " + dbUser + "/" + dbHost;
}
}
15. 4. Logger 설정
사용하려는 class 내부에 다음을 선언(예: app.controller.ts)
method 내부에서 사용
결과 Console
private readonly logger = new Logger(AppController.name);
this.logger.log(userDto);
16. 5. session 설정
필요 모듈 설치
main.ts 에 session 설정 추가
$ npm i express-session
$ npm i -D @types/express-session
import * as session from 'express-session’;
// somewhere in your initialization file
app.use(
session({
secret: 'my-secret',
resave: false,
saveUninitialized: false,
}),
);
17. 5. session 사용
app.controller.ts
Request는 express를 사용
결과 :
import { Request } from 'express';
@Get('/visits')
findAll(@Req() req: Request): string {
req.session["visits"] = req.session["visits"]
? req.session["visits"] + 1 : 1;
return "My VISITS : " + req.session["visits"];
}
18. 6. helmet & cors 설정
helmet 모듈 설치
helmet 모듈 사용(main.ts)
cors 사용(main.ts)
$ npm i --save helmet
import * as helmet from 'helmet';
app.use(helmet());
app.enableCors();
19. 7. HttpModule 사용
사용 선언(예 : app.module.ts)
사용 예 (app.controller.ts)
@Module({
imports: [ConfigModule.forRoot(), HttpModule],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
@Get('/httpTest')
async callMockHtt(): Promise<any> {
const res = await this.httpService.get('htt
p://jsonplaceholder.typicode.com/todos/1').toPr
omise();
return res.data;
}
20. 전체 소스 보기
https://github.com/lahuman/nestjs_101
21. 참고 자료
NestJS : https://nestjs.com
NestJS Documents : https://docs.nestjs.com