[TIL] Express

Dev_minยท2019๋…„ 10์›” 28์ผ
0

TIL

๋ชฉ๋ก ๋ณด๊ธฐ
27/61

๐Ÿ‘‰ ๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ

  • users, cafes, comments db schema
  • express ๊ธฐ๋ณธ ์„œ๋ฒ„ ๊ตฌ์ถ•(MVC pattern)
  • ์„œ์šธ ์ง€๋„ api

๐Ÿ‘‰ Express-generator

npm i -g express-generator

ํด๋” ๊ตฌ์กฐ

  • app.js ํŒŒ์ผ์ด ํ•ต์‹ฌ์ ์ธ ์„œ๋ฒ„ ์—ญํ• 
  • binํด๋”์˜ wwwํŒŒ์ผ์€ ์„œ๋ฒ„๋ฅผ ์‹คํ–‰ํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ
  • public ํด๋”๋Š” ์™ธ๋ถ€์—์„œ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•œ ํŒŒ์ผ๋“ค์„ ๋ชจ์•„๋‘” ๊ณณ
  • routesํด๋”๋Š” ์ฃผ์†Œ๋ณ„ ๋ผ์šฐํ„ฐ๋“ค์„ ๋ชจ๋‹ค์šด ๊ณณ์ด๊ณ , viewsํด๋”๋Š” ํ…œํ”Œ๋ฆฟ ํŒŒ์ผ์„ ๋ชจ์•„๋‘” ๊ณณ

์„œ๋ฒ„ ๋กœ์ง : routes ํด๋” / ํ™”๋ฉด ๋ถ€๋ถ„ : viewsํด๋” / ๋ฐ์ดํ„ฐ ๋ถ€๋ถ„ : models ํด๋”
bin/www ํŒŒ์ผ์€ http ๋ชจ๋“ˆ์— express๋ชจ๋“ˆ์„ ์—ฐ๊ฒฐํ•˜๊ณ , ํฌํŠธ๋ฅผ ์ง€์ •ํ•˜๋Š” ๋ถ€๋ถ„

var app = require('../app');
var debug = require('debug')('learn-express:server');
var http = require('http');
 
var port = normalizePort(process.env.PORT || '3000');
// process.env ๊ฐ์ฒด์— PORT์†์„ฑ์ด ์žˆ๋‹ค๋ฉด ๊ทธ ๊ฐ’์„ ์‚ฌ์šฉ
app.set('port', port);
 
var server = http.createServer(app);
 
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);


์ถœ์ฒ˜: https://backback.tistory.com/329 [Back Ground]

๐Ÿ‘‰ Sequelize CLI

: Sequelize๋Š” Node.js์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ORM
: Sequelize CLI๋Š” ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ž‘์—…์„ ํ•  ์ˆ˜ ์žˆ๋Š” ํˆด. ๊ธฐ๋Šฅ๋“ค๋กœ๋Š” ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜, ์‹œ๋“œ, ๋ชจ๋ธ์ด ์žˆ๋‹ค.

ORM ์žฅ์ 
1. ORM์„ ํ†ตํ•ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ฟผ๋ฆฌ๋ฅผ ์ถ”์ƒํ™”ํ•ด ๋ณธ๋ž˜ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๋Š” ๋กœ์ง์—๋งŒ ์ง‘์ค‘
2. ํŠน์ • ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋Œ€ํ•œ ์ข…์†์„ฑ์ด ์‚ฌ๋ผ์ ธ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๊ฐ€ ๋ฐ”๋€Œ๋Š” ์ƒํ™ฉ์—๋„ ์œ ์—ฐํ•˜๊ฒŒ ๋Œ€์ฒ˜
3. ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜์„ ์‰ฝ๊ฒŒ ๊ฐ€๋Šฅ

Sequelize CLI ๋ชจ๋ธ ์ •์˜ ๋ฐ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ : ์ฝ”๋“œ์— ์ ํ˜€์ ธ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ…Œ์ด๋ธ”์— ๋Œ€ํ•ด์„œ ์‹ค์ œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ํ…Œ์ด๋ธ”์„ ์ƒ์„ฑํ•˜๋Š” ๊ฐœ๋…

profile
TIL record

0๊ฐœ์˜ ๋Œ“๊ธ€