본문 바로가기

Develop/[NestJs]

(31)
[NestJs] 게시판 정보 불러오기 및 게시판 마무리 board controller import { Body, Controller, Get, Post } from '@nestjs/common'; import { BoardsService } from './boards.service'; import {Board} from './board.model' @Controller('boards') export class BoardsController { constructor(private boardService: BoardsService){} @Get('/') getAllBoard(): Board[]{ return this.boardService.getAllBoards(); } @Post('/create') createBoard(@Body('title') title: ..
[NestJS] CRUD 본격적으로 시작해보기 일단 로컬 데이터를 기반으로 컨트롤러, 서비스를 연결해보자 Controller import { Controller, Get } from '@nestjs/common'; import { BoardsService } from './boards.service'; @Controller('boards') export class BoardsController { constructor(private boardService: BoardsService){} @Get('') getAllBoard(){ return this.boardService.getAllBoards(); } } Service import { Injectable } from '@nestjs/common'; @Injectable() export class ..
[NestJS] 모듈, 컨트롤러, 서비스 생성 하기 우선 NestJS모듈은, @Module () 데코레이터로 주석이 달린 클래스이다. AppMoudle은 하나 이상있어야 하고, appMoudule은 시작점이다. 하위에 여러 모듈이 존재할 수 있고, CURD 관련 모듈 게시판, 사용자에대한 모듈 두개를 만들어 보자 * 모듈은 싱글톤이고, 여러 모듈간에 쉽게 공통적으로 인스턴스를 공유할 수 있다. 1) BoardModule 생성하기 > nest g module boards 모듈안에 아래와 같이 구성이 되게끔 만들것이다. Controller,Entity,Service,Repo,Validataion들을 생성해보자 1) Controller생성해보기 Controller는 데코레이터로 정의를 해야한다. 핸들러는 메소드를 정의해주어야 한다. @Get,@Post,@Put..
[NestJs] 간단하게 동작과정에 대해서 살펴보기 우선 기본 동작이 어떻게 되는지 보자. 1) main.ts main.ts에서 AppModule로 NestFactory를 생성하고, 해당 안에서는 appcontroller,appservice가 있게된다. 그리고, /로 접근시 서비스의 hello world를 리턴하고, 이를 화면에 보여주게 된다.
[NestJS] 간단하게 내부 프로젝트 구성 살펴보기 nest new ./로 하면 mkdir하고 안에 들어가서 하면 내부를 자동생성하게 해준다. 자동 생성되는 파일에 대해서 살펴보자 1) eslintrc.js 개발자들이 특정한 규칙을 가지고 코드를 깔끔하게 짤수있게 도와주는 라이브러리 타입 스크립트 관련 문법 체크를 해준다. 2)prettierrc 코드의 형식을 맞춰준다. 포매터라고 생각하면된다. 3) nest-cli.json nest프로젝트 설정 할수 있게 해주는 json파일 4)tsconfig.json 어떻게 타입스크립트를 컴파일 할지 설정 5) package.json 프로젝트 이름, 의존성 등을 정의하는 파일이다. 6)main.ts application이 생성되고, AppModule을 만들어주는 부분에 해당된다. 해당 root Module 하위에 다른..
[NestJs] NestJS 환경 세팅 1. Nodejs 설치 https://nodejs.org/ko/download 다운로드 | Node.js Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. nodejs.org 여기서 설치하면된다. 2. NestJS CLI 설치 sudo npm i -g @nestjs/cli 3. 설치확인 nest --version nest new nestjs-test npm을 선택해주면, nestjs-test프로젝트 내에 많은 소스들이 자동 생성된다. 4. 프로젝트 확인
[NestJs] NestJs란? 새로운 사이드 플젝에서 NestJs라는 걸 사용하게 되었다. 아... 백엔드로 java script라니 ㅋㅋ ;; 무튼 공부해보자 파이썬은 장고 자바는 스프링 js,ts에서는 NestJS라고 한단다 ㅋㅋ 플러그인 확장과, 왠만한 기능은 내장하고 있고 스프링 관련 내용과도.. 좀 있다고한단다 ㅋㅋ 무튼 사실 이런저런 이점이 있으니까 누군가가 이렇게 쓰고, 사용하고 하겠지... 이런건 중요하지 않으니 바로 실습 및 세팅해서 진행해보자