가을기 Workspace

NestJS 시작하기 본문

개발/nodejs

NestJS 시작하기

가을기_ 2021. 5. 9. 00:45

본 포스팅은 사이드프로젝트 스케치데브를 사용하면서 공부한 nestjs를 정리한 글입니다.

스케치데브가 궁금하시다면: https://sketchdev.kr

 

스케치데브 - 개발자 캐치마인드

스케치데브는 개발자들만의 IT용어로 즐기는 스케치퀴즈 연상 캐치마인드 게임입니다. 고득점을 한번 노려보세요!

sketchdev.kr

호랑이인줄 알았는데

 

홈페이지 들어가보면 고양이가 반겨준다. 귀엽다.

 

 

node.js 프레임워크

Spring 창시자가 합류해서 만든 것으로 유명하다.

얘가 http server 를 제공하는 등의 특정한 기능을 해주는건 아니고,

express, mongoose 등 만들어져있는 걸 모듈화, 조립 잘하게 만들 수 있게 해주는 프레임워크다.

철학

Philosophy

In recent years, thanks to Node.js, JavaScript has become the “lingua franca” of the web for both front and backend applications. This has given rise to awesome projects like AngularReact and Vue, which improve developer productivity and enable the creation of fast, testable, and extensible frontend applications. However, while plenty of superb libraries, helpers, and tools exist for Node (and server-side JavaScript), none of them effectively solve the main problem of - Architecture.

Nest provides an out-of-the-box application architecture which allows developers and teams to create highly testable, scalable, loosely coupled, and easily maintainable applications. The architecture is heavily inspired by Angular.

요약하자면 node.js가 코드 구조를 지금까지 고민한적 없으니, Nest가 조립할 수 있는 프레임워크를 제공하겠다는 것. Angular의 영감을 받았다고 한다.

 

코드

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

@Controller('cats')
export class CatsController {
  @Get()
  findAll(): string {
    return 'This action returns all cats';
  }
}


import { Injectable } from '@nestjs/common';
import { Cat } from './interfaces/cat.interface';

@Injectable()
export class CatsService {
  private readonly cats: Cat[] = [];

  create(cat: Cat) {
    this.cats.push(cat);
  }

  findAll(): Cat[] {
    return this.cats;
  }
}

사용하고있는 대표적인 기업: 당근마켓, 네이버

첫 시작

시작하는 법은 아주 간단하다.

$ npm i -g @nestjs/cli
$ nest new project-name

nest-cli 를 설치하고 싶지 않다면, 아래처럼 하면 된다.

$ git clone https://github.com/nestjs/typescript-starter.git project
$ cd project
$ npm install
$ npm run start

 

함꼐보면 좋은 글

 

 

'개발 > nodejs' 카테고리의 다른 글

Typescript로 object 초기화  (0) 2021.06.16
NestJS mongodb module  (0) 2021.05.09
NestJS module  (0) 2021.05.09
NestJS provider  (0) 2021.05.09
NestJS controller  (0) 2021.05.09
Comments