๋ฐ์ํ
Node.js
Node.js๋ Chrome V8 JavaScript ์์ง์ผ๋ก ๋น๋๋ JavaScript ๋ฐํ์์ ๋๋ค
- ๊ฐ๋ฐ์๋ ์๋ฒ ์ฌ์ด๋์ ๋คํธ์ํน ์ ํ๋ฆฌ์ผ์ด์ ์ ๋น๋กฏํ ๋ค์ํ ์ ํ์ ์ํํธ์จ์ด๋ฅผ JavaScript๋ก ๊ฐ๋ฐํ ์ ์์ต๋๋ค.
- Node.js๋ ๋น๋๊ธฐ ์ด๋ฒคํธ ์ฃผ๋ ์ํคํ ์ฒ๋ฅผ ์ฌ์ฉํ์ฌ ๊ฒฝ๋ํ ๋ฐ ํจ์จ์ฑ์ ๊ฐ์กฐํ๋ฉฐ, ์ด๋ ํนํ ๋ฐ์ดํฐ ์ง์ฝ์ ์ธ ์ค์๊ฐ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ตฌ์ถํ๋ ๋ฐ ์ ํฉํฉ๋๋ค.
- ์ฃผ์ ํน์ง์ ์๋์ ๊ฐ์ต๋๋ค.
- ๋น๋๊ธฐ ๋ฐ ์ด๋ฒคํธ ์ฃผ๋: ๋ชจ๋ API๋ ๋น๋๊ธฐ์ ์ผ๋ก ์๋ํ๋ฉฐ, ์ด๋ Node.js ์๋ฒ๊ฐ I/O ์์ ์ ๊ธฐ๋ค๋ฆฌ์ง ์๊ณ ๋ค์ ์์ ์ผ๋ก ๋์ด๊ฐ ์ ์์์ ์๋ฏธํฉ๋๋ค. ์ด๋ ๋์ ๋์์ฑ ์ฒ๋ฆฌ ๋ฅ๋ ฅ์ ์ ๊ณตํฉ๋๋ค.
- ๋จ์ผ ์ค๋ ๋ ๋ชจ๋ธ with ์ด๋ฒคํธ ๋ฃจํ: Node.js๋ ๋ฉํฐ ์ค๋ ๋ ํ๋ก๊ทธ๋๋ฐ ๋์ ์ด๋ฒคํธ ๋ฃจํ๋ฅผ ์ฌ์ฉํ ๋จ์ผ ์ค๋ ๋ ๋ชจ๋ธ์ ์ฑํํ์ฌ ๋ฆฌ์์ค๋ฅผ ํจ์จ์ ์ผ๋ก ์ฌ์ฉํฉ๋๋ค.
- ํฌ๋ก์ค ํ๋ซํผ: Node.js ์ ํ๋ฆฌ์ผ์ด์ ์ Windows, Linux, Unix, Mac OS X ๋ฑ ๋ค์ํ ํ๋ซํผ์์ ์คํ๋ ์ ์์ต๋๋ค.
- NPM(Node Package Manager): Node.js์ ํจํค์ง ๊ด๋ฆฌ์๋ก, ์๋ง์ ์คํ ์์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ชจ๋์ ์ ๊ณตํ์ฌ ๊ฐ๋ฐ์๊ฐ ์์ฝ๊ฒ ์ฌ์ฉํ ์ ์๋๋ก ํฉ๋๋ค.
- ๊ทธ๋ฆฌ๊ณ ์น ์๋ฒ, ๋ฐฑ์๋ API ์๋น์ค, ์ค์๊ฐ ํต์ ์ ํ๋ฆฌ์ผ์ด์ ๋ฑ์ ๊ฐ๋ฐํ๋ ๋ฐ ๋๋ฆฌ ์ฌ์ฉ๋ฉ๋๋ค.
- ๋ํ Node.js๋ ๊ทธ ์์ฒด๋ก ์ ์ฒด ์คํ์ ์ ๊ณตํ์ง๋ ์์ง๋ง, Express ๊ฐ์ ํ๋ ์์ํฌ์ ๊ฒฐํฉํ์ฌ ํ ์คํ ๊ฐ๋ฐ ํ๊ฒฝ์ ๊ตฌ์ฑํ ์ ์์ต๋๋ค.
NPM
npm์ Node.js ํจํค์ง ๊ด๋ฆฌ์(Node Package Manager)์ ์ฝ์๋ก, Node.js๋ก ๋ง๋ค์ด์ง ๋ชจ๋ ๋๋ ํจํค์ง๋ฅผ ๊ด๋ฆฌํ๋ ๋๊ตฌ์ ๋๋ค.
- ๊ฐ๋ฐ์๋ค์ด ์์ฑํ ์๋ง์ ์คํ์์ค Node.js ํจํค์ง๋ค์ ๊ณต์ ํ๊ณ ์ฌ์ฉํ ์ ์๋ ์ค์ ์ ์ฅ์ ์ญํ ์ ํฉ๋๋ค.
- npm์ ํตํด ๊ฐ๋ฐ์๋ค์ ํ์ํ Node.js ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ๋๊ตฌ๋ค์ ์ฝ๊ฒ ์ฐพ์์ ์ค์นํ ์ ์์ผ๋ฉฐ, ์์ ์ด ๊ฐ๋ฐํ ํจํค์ง๋ฅผ npm์ ๋ฑ๋กํ์ฌ ์ ์ธ๊ณ ๋ค๋ฅธ ๊ฐ๋ฐ์๋ค๊ณผ ๊ณต์ ํ ์๋ ์์ต๋๋ค.
- npm์ ์ฃผ์ ๊ธฐ๋ฅ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
- ํจํค์ง ์ค์น: `npm install` ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ ํ์ํ Node.js ํจํค์ง๋ฅผ ์ค์นํ ์ ์์ต๋๋ค. ํน์ ๋ฒ์ ์ ์ง์ ํ๊ฑฐ๋ ์ต์ ๋ฒ์ ์ ์๋์ผ๋ก ์ค์นํ ์๋ ์์ต๋๋ค.
- ์์กด์ฑ ๊ด๋ฆฌ: ํ๋ก์ ํธ์ `package.json` ํ์ผ์๋ ํด๋น ํ๋ก์ ํธ๊ฐ ์์กดํ๋ ๋ชจ๋ ํจํค์ง๋ค์ ๋ชฉ๋ก๊ณผ ๋ฒ์ ์ ๋ณด๊ฐ ์ ์ฅ๋ฉ๋๋ค. npm์ ์ด ํ์ผ์ ์ฌ์ฉํ์ฌ ํ๋ก์ ํธ์ ์์กด์ฑ์ ๊ด๋ฆฌํฉ๋๋ค.
- ์คํฌ๋ฆฝํธ ์คํ: `package.json` ํ์ผ์๋ ํ๋ก์ ํธ์ ๊ด๋ จ๋ ์คํฌ๋ฆฝํธ๋ฅผ ์ ์ํ ์ ์์ผ๋ฉฐ, `npm run` ๋ช ๋ น์ด๋ฅผ ํตํด ์ด๋ฌํ ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ ์ ์์ต๋๋ค.
- ํจํค์ง ๋ฐฐํฌ: ๊ฐ๋ฐํ ํจํค์ง๋ฅผ npm์ ๋ฐฐํฌํ์ฌ ์ ์ธ๊ณ ๋ค๋ฅธ ๊ฐ๋ฐ์๋ค๊ณผ ๊ณต์ ํ ์ ์์ต๋๋ค.
- npm์ Node.js ๊ฐ๋ฐ์ ์์ด ํ์์ ์ธ ๋๊ตฌ๋ก, Node.js์ ํจ๊ป ์ค์น๋ฉ๋๋ค.
Node.js & NPM ์ํธ์์ฉ
๋ ๊ธฐ์ ์ Node.js ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ฐ๋ฐ, ๋ฐฐํฌ, ๊ด๋ฆฌํ๋ ๊ณผ์ ์์ ์๋ก ๋ณด์์ ์ธ ๊ด๊ณ๋ฅผ ๊ฐ์ง๋๋ค.
- ํจํค์ง ์ค์น ๋ฐ ๊ด๋ฆฌ: Node.js๋ก ๊ฐ๋ฐ๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ค์ํ ์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ชจ๋์ ํ์๋ก ํฉ๋๋ค. npm์ ์ฌ์ฉํ๋ฉด ์ด๋ฌํ ์์กด์ฑ์ ์ฝ๊ฒ ๊ด๋ฆฌํ๊ณ , ํ์ํ ํจํค์ง๋ฅผ ์ค์นํ ์ ์์ต๋๋ค. npm install <ํจํค์ง๋ช > ๋ช ๋ น์ด๋ฅผ ํตํด ํ์ํ ํจํค์ง๋ฅผ ์ค์นํ๊ณ , ์ด๋ฌํ ์์กด์ฑ์ package.json ํ์ผ์ ์๋์ผ๋ก ๊ธฐ๋ก๋ฉ๋๋ค.
- ํ๋ก์ ํธ ์ค์ : Node.js ํ๋ก์ ํธ๋ฅผ ์์ํ ๋, npm init ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ ๊ธฐ๋ณธ์ ์ธ package.json ํ์ผ์ ์์ฑํ ์ ์์ต๋๋ค. ์ด ํ์ผ์๋ ํ๋ก์ ํธ์ ๋ฉํ๋ฐ์ดํฐ์ ์์กด์ฑ ์ ๋ณด๊ฐ ๋ด๊ฒจ ์์ผ๋ฉฐ, ํ๋ก์ ํธ์ ๊ตฌ์ฑ๊ณผ ๊ด๋ฆฌ์ ์ค์ํ ์ญํ ์ ํฉ๋๋ค.
- ์คํฌ๋ฆฝํธ ์คํ: ๊ฐ๋ฐ ๊ณผ์ ์์ ์์ฃผ ์คํ๋๋ ๋ช ๋ น์ด๋ค์ package.json ํ์ผ์ scripts ์น์ ์ ์ ์ํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด, ์ ํ๋ฆฌ์ผ์ด์ ์ ์คํํ๊ฑฐ๋ ํ ์คํธ ์ฝ๋๋ฅผ ์คํํ๋ ์คํฌ๋ฆฝํธ๋ฅผ ์ ์ํ ์ ์์ผ๋ฉฐ, npm run <์คํฌ๋ฆฝํธ๋ช > ๋ช ๋ น์ด๋ก ์ด๋ฅผ ์คํํ ์ ์์ต๋๋ค.
- ํจํค์ง ๊ณต์ ๋ฐ ๋ฐฐํฌ: ๊ฐ๋ฐ์๊ฐ ์ง์ ๊ฐ๋ฐํ Node.js ๋ชจ๋์ด๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ npm์ ํตํด ๊ณต์ ํ ์ ์์ต๋๋ค. npm publish ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ๋ฉด ์ ์ธ๊ณ์ ๋ค๋ฅธ ๊ฐ๋ฐ์๋ค์ด ํด๋น ํจํค์ง๋ฅผ ์ค์นํ์ฌ ์ฌ์ฉํ ์ ์๊ฒ ๋ฉ๋๋ค.
- Node.js์ npm์ ์ํธ์์ฉ์ Node.js ์ํ๊ณ์์ ํจ์จ์ ์ธ ๋ชจ๋ ๊ด๋ฆฌ์ ์ฝ๋ ์ฌ์ฌ์ฉ์ ๊ฐ๋ฅํ๊ฒ ํฉ๋๋ค.
๋ฐ์ํ
'๐ Backend' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Backend] Json, Babel (0) | 2024.05.10 |
---|