오전시간에는 국취제 면담을 다녀왔고, aws 강의를 수강하고 있습니다.
그리고 sql 2회차가 나왔다고 하여서 강의영상은 아직 나오지 않았기 때문에 문제를 먼저 풀어보려고 합니다.
면담을 다녀온 후 node.js를 하는데 정작 어느 부분에서 취업을 해야할지 고민이 많아 찾아보니 node.js를 사용하는데 같이 쓰이는 것이 typescript, express, nest.js 가 나와서 nest.js를 들으려고 합니다. 다듣기에는 무리지만 필요할거 같아 다 듣는것이 목표입니다.
nestjs 설치
<gitbash로 작성함>
$ mkdir nestjs_practice
$ npm i -g @nestjs/cli
$ nest
Usage: nest <command> [options]
Options:
-v, --version Output the current version.
-h, --help Output usage information.
Commands:
new|n [options] [name] Generate Nest application.
build [options] [app] Build Nest application.
start [options] [app] Run Nest application.
info|i Display Nest project details.
add [options] <library> Adds support for an external library to your project.
generate|g [options] <schematic> [name] [path] Generate a Nest element.
Schematics available on @nestjs/schematics collection:
┌───────────────┬─────────────┬──────────────────────────────────────────────┐
│ name │ alias │ description │
│ application │ application │ Generate a new application workspace │
│ class │ cl │ Generate a new class │
│ configuration │ config │ Generate a CLI configuration file │
│ controller │ co │ Generate a controller declaration │
│ decorator │ d │ Generate a custom decorator │
│ filter │ f │ Generate a filter declaration │
│ gateway │ ga │ Generate a gateway declaration │
│ guard │ gu │ Generate a guard declaration │
│ interceptor │ itc │ Generate an interceptor declaration │
│ interface │ itf │ Generate an interface │
│ library │ lib │ Generate a new library within a monorepo │
│ middleware │ mi │ Generate a middleware declaration │
│ module │ mo │ Generate a module declaration │
│ pipe │ pi │ Generate a pipe declaration │
│ provider │ pr │ Generate a provider declaration │
│ resolver │ r │ Generate a GraphQL resolver declaration │
│ resource │ res │ Generate a new CRUD resource │
│ service │ s │ Generate a service declaration │
│ sub-app │ app │ Generate a new application within a monorepo │
└───────────────┴─────────────┴──────────────────────────────────────────────┘
$ nest new sparta-nest
? Which package manager would you ❤️ to use? (Use arrow keys)
❯ npm
yarn
pnpm
? Which package manager would you ❤️ to use? (Use arrow keys)
? Which package manager would you ❤️ to use? npm
CREATE sparta-nest/.eslintrc.js (663 bytes)
CREATE sparta-nest/.prettierrc (51 bytes)
CREATE sparta-nest/nest-cli.json (171 bytes)
CREATE sparta-nest/package.json (1956 bytes)
CREATE sparta-nest/README.md (3340 bytes)
CREATE sparta-nest/tsconfig.build.json (97 bytes)
CREATE sparta-nest/tsconfig.json (546 bytes)
CREATE sparta-nest/src/app.controller.spec.ts (617 bytes)
CREATE sparta-nest/src/app.controller.ts (274 bytes)
CREATE sparta-nest/src/app.module.ts (249 bytes)
CREATE sparta-nest/src/app.service.ts (142 bytes)
CREATE sparta-nest/src/main.ts (208 bytes)
CREATE sparta-nest/test/app.e2e-spec.ts (630 bytes)
CREATE sparta-nest/test/jest-e2e.json (183 bytes)
- Installation in progress... ☕
√ Installation in progress... ☕
🚀 Successfully created project sparta-nest
👉 Get started with the following commands:
$ cd sparta-nest
$ npm run start
Thanks for installing Nest 🙏
Please consider donating to our open collective
to help us maintain this package.
🍷 Donate: https://opencollective.com/nest
$ git clone https://github.com/nestjs/typescript-starter.git sparta-nest
$ cd sparta-nest
$ npm i
-- aws RDS 일시중지 함 --
Inversion of Control 준말
제어역전 이라고도 함
기존에 서비스를 사용하고 싶을땐 아래와 같이 코드 작성
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
@Controller()
export class AppController {
// 1. 사용하고 싶은 서비스 타입 객체를 미리 선언합니다.
private appService: AppService
constructor() {
// 2. 생성자에서 실제로 사용할 서비스 객체를 직접 생성합니다.
this.appService = new AppService();
}
...
}
IoC는 모듈 간 결합도를 낮추기 때문에 하나의 모듈이 변경되어도
다른 모듈들에는 영향을 최소화되어 웹 어플리케이션을 지속 가능하고
확장성 있게 해줍니다
제어권을 넘겨주면 개발자는 비지니스 로직을 작성하는 데 더 집중을 할 수 있습니다. 비지니스 로직을 작성하기 위해 세팅해야 하는 사전작업이 최소화되는 것이에요.
constructor(private readonly appService: AppService) {} // 얼마나 편하게요~
추가 알아볼 자료
글 재미있게 봤습니다.