ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

Node.js๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , Typescript๋ฅผ ๋ฐฐ์šฐ๋˜ ์™€์ค‘์— ์ ‘ํ–ˆ๋˜ ํ”„๋ ˆ์ž„์›Œํฌ์ธ NestJS๋ผ๋Š” ๋ฌผ๊ฑด์„ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
๊ธฐ์กด์—” Express๋ฅผ ์‚ฌ์šฉํ–ˆ์—ˆ๊ณ , ๊ทธ ์•ˆ์— Typescript๋ฅผ ์…‹ํŒ…ํ•˜์—ฌ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ตฌ์„ฑํ–ˆ๋˜ ๊ฒƒ๊ณผ๋Š” ๋‹ค๋ฅด๊ฒŒ ์ด ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์“ฐ๊ฒŒ๋˜๋ฉด ๊ธฐ๋ณธ์ ์ธ Typescript ์…‹ํŒ…๋ถ€ํ„ฐ ์ „์ฒด์ ์ธ ๊ตฌ์กฐ๊นŒ์ง€ ํ”„๋ ˆ์ž„์›Œํฌ ์ƒ์„ฑ ์ปค๋งจ๋“œ๋ฅผ ํ†ตํ•ด ๊ธฐ๋ณธ์ ์œผ๋กœ ์ œ๊ณตํ•ด์ค๋‹ˆ๋‹ค. ๊ณต์‹ ๋ฌธ์„œ์—์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์†Œ๊ฐœํ•ฉ๋‹ˆ๋‹ค.

๋”๋ณด๊ธฐ

Nest (NestJS) is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with and fully supports TypeScript (yet still enables developers to code in pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).

Under the hood, Nest makes use of robust HTTP Server frameworks like Express (the default) and optionally can be configured to use Fastify as well!

Nest provides a level of abstraction above these common Node.js frameworks (Express/Fastify), but also exposes their APIs directly to the developer. This gives developers the freedom to use the myriad of third-party modules which are available for the underlying platform.

[์ถœ์ฒ˜ - https://docs.nestjs.com/]

์ง์ ‘ ์‚ฌ์šฉํ•ด๋ณด๋ฉด์„œ ๋Š๊ผˆ๋˜๊ฑฐ์ง€๋งŒ ์•ฝ๊ฐ„ Spring ๊ฐ™์€ ๋Š๋‚Œ์ด ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.
๊ธฐ์กด์— ๋ฐ”๋‹๋ผ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ๊ตฌ์„ฑํ•˜๋˜ ๋ชจ์–‘์ƒˆ์™€๋Š” ๋‹ฌ๋ฆฌ OOP(๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ)์˜ ์š”์†Œ๊ฐ€ ๊ฐ•๋ ฅํ•˜๊ฒŒ ๋Š๊ปด์กŒ์Šต๋‹ˆ๋‹ค.
๊ณต์‹ ๋ฌธ์„œ์—์„œ ๊ฐ€์ด๋“œํ•ด์ฃผ๋Š” ์‹œ์ž‘๋Œ€๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋ฉด ๊ต‰์žฅํžˆ ์‰ฝ๊ฒŒ ์›น์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ณ , ์•„์ฃผ ๊น”๋”ํ•˜๊ฒŒ ํ”„๋กœ์ ํŠธ์˜ ๊ตฌ์กฐ๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

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

์œ„์™€๊ฐ™์ด ์ปค๋งจ๋“œ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด package manager๋กœ ๋ฌด์—‡์„ ์“ธ์ง€ ๋ฌผ์–ด๋ณด๋Š”๋ฐ
๊ทธ๊ฑด ์ทจํ–ฅ์— ๋งž๊ฒŒ๋” ์„ ํƒํ•˜์‹œ๋ฉด ์ด๋Ÿฐ ๊ตฌ์กฐ์˜ ํ”„๋กœ์ ํŠธ๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

test๋ชจ๋“ˆ๊ณผ ๊ธฐํƒ€ ์„ค์ •ํŒŒ์ผ๋“ค์€ ์ œ์ณ๋‘๊ณ  src๋””๋ ‰ํ† ๋ฆฌ ์•ˆ์— ํŒŒ์ผ๋“ค์„ ๋ณด์‹œ๋ฉด ๋˜๋Š”๋ฐ ๊ธฐ๋ณธ์ ์œผ๋กœ ์„ธ๊ฐ€์ง€์˜ ๊ตฌ์„ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค.
๋ฌผ๋ก  ์ผ๋ฐ˜์ ์ธ ๋””๋ ‰ํ† ๋ฆฌ ๊ตฌ์กฐ๋Š” ์•„๋‹ˆ๊ณ  ์•ฑ์„ ๊ตฌ๋™ํ•˜๊ธฐ ์œ„ํ•œ ๊ธฐ๋ณธ ๊ตฌ์„ฑ๋งŒ์„ ์ƒ์„ฑํ•ด์ค๋‹ˆ๋‹ค.

  • Controller : ์ปจํŠธ๋กค๋Ÿฌ๋Š” ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๊ณ  ํด๋ผ์ด์–ธํŠธ์— ์‘๋‹ต์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค.
  • Module : Nest๊ฐ€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ตฌ์กฐ๋ฅผ ๋งŒ๋“ค๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ๋ฅผ ์ œ๊ณตํ•ด์ฃผ๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค. ๋‚ด์šฉ์ด ์กฐ๊ธˆ ํ—ท๊ฐˆ๋ฆฌ๋Š”๋ฐ ๊ตณ์ด ๋น„์œ ๋ฅผ ํ•˜์ž๋ฉด Module์— Controller๋‚˜ Service๋“ฑ์„ ์ถ”๊ฐ€ํ•˜์—ฌ ํŠน์ • ๊ธฐ๋Šฅ์„ ๊ฐ€์ง€๋Š” ๋ชจ๋“ˆ๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ์‹œ์— ๊ธฐ๋ณธ์ ์œผ๋กœ ๋งŒ๋“ค์–ด์ง„ ๋ชจ๋“ˆ์€ ๋ฃจํŠธ๋ชจ๋“ˆ์ž…๋‹ˆ๋‹ค.
  • Service : ์„œ๋น„์Šค, ๋ง๊ทธ๋Œ€๋กœ ์„œ๋น„์Šค๋ฅผ ํ•˜๊ธฐ์œ„ํ•œ ๋กœ์ง์„ ๋‹ด๊ณ ์žˆ๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค.

NestJS๋Š” Typescript๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋งŒ๋“ค์–ด์ง„ ํ”„๋ ˆ์ž„์›Œํฌ๊ธฐ๋•Œ๋ฌธ์— ๊ธฐ๋ณธ์ ์œผ๋กœ ๋นŒ๋“œ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
๊ทธ๋ž˜์„œ nest build ๋ช…๋ น์–ด๋ฅผ ์“ฐ๋ฉด tsconfig ์„ค์ •์„ ์ด์šฉํ•˜์—ฌ Typescript ๋นŒ๋“œ๋ฅผ ํ•˜๊ณ  ๋นŒ๋“œ๋œ js ํŒŒ์ผ์„ node ๋ช…๋ น์–ด๋กœ ์‹คํ–‰์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
npm ํ˜น์€ yarn start ๋ช…๋ น์–ด๋กœ ์‹คํ–‰์„ ํ•˜๋ฉด ์•„์ฃผ ๊ฐ„๋‹จํ•˜๊ฒŒ 3000 ํฌํŠธ๋กœ ์›น์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ•˜๋‚˜๊ฐ€ ๋œจ๊ฒŒ๋ฉ๋‹ˆ๋‹ค.
์‹œ์ž‘์€ ๊ต‰์žฅํžˆ ๊ฐ„๋‹จํ•˜์ฃ ? ๊ทธ๋Ÿผ ๊ตณ์ด ์ด๋Ÿฐ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์™œ ์จ์•ผํ• ๊นŒ ์‹ถ์—ˆ๋Š”๋ฐ ์‚ฌ์šฉํ•˜๋‹ค๋ณด๋‹ˆ NestJS์˜ ์—ฌ๋Ÿฌ ๊ธฐ๋Šฅ๋“ค์ด ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.
๋‹ค์–‘ํ•œ ์–ด๋…ธํ…Œ์ด์…˜ ์ง€์›๊ณผ ์•„ํ‚คํ…์ณ๊ฐ€ ๋ช…ํ™•ํ•˜๊ณ  ๊ทธ์—๋”ฐ๋ฅธ ๊ฐ์ข… ๊ธฐ๋Šฅ๋“ค์„ ๊ณต์‹์ ์œผ๋กœ ์ง€์›ํ•ด์ฃผ๊ณ ์žˆ๊ธฐ๋•Œ๋ฌธ์— ํฐ ๋ฌด๋ฆฌ์—†์ด ํ”„๋กœ์ ํŠธ๋ฅผ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ๋ถ€๋ถ„๋“ค์€ ๋‹ค๋ฅธ ๊ธ€์—์„œ ๋‹ด์•„๋ณผ ์ˆ˜ ์žˆ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๋Œ“๊ธ€
๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
๋งํฌ
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
๊ธ€ ๋ณด๊ด€ํ•จ