Download pdf - Node.js 기본과정

Transcript
Page 1: Node.js 기본과정

Node.js 기본과정

신촌 크레바스 스터디 - 2주차 첫번째

Socket.io 까지

홍석유[email protected]

Page 2: Node.js 기본과정

교재1.�모던 웹을 위한Node.js 프로그래밍

2. Udemy 강의 - https://www.udemy.com/understand-nodejs

3. T아카데미 수업 - https://tacademy.sktechx.com/live/player/listOnline.action

4. 아마존 웹서비스2주차 첫번째 스터디 ­ Node.js

Page 3: Node.js 기본과정

2주차 첫번째 스터디 ­ Node.js

Node.js

RUBY

Ruby�on�Rails

Node.js

Express

Page 4: Node.js 기본과정

async I/Oevent -driven

+a멀티쓰레드?

2주차 첫번째 스터디 ­ Node.js

Page 5: Node.js 기본과정

2주차 첫번째 스터디 ­ Node.js

모듈내부모듈 외부모듈

fs,�http

mysql,�mongoose,�aws-sdk,�express,�

body-parser,�jade,��ejs,�underscore,�

socket.io,�supervisor,

NPM

gem

Page 6: Node.js 기본과정

2주차 첫번째 스터디 ­ Node.js

Doc(공식문서)

var fs=require('fs');

//Asyncfs.readFile('data.txt',{encoding:'utf8'}, function(err,data){console.log(data);

})

https://nodejs.org/en/docs

Page 7: Node.js 기본과정

2주차 첫번째 스터디 ­ Node.js

-g

--save

package.json

https://www.npmjs.com

Page 8: Node.js 기본과정

2주차 첫번째 스터디 ­ Node.js

sync�vs.�asyncvar fs=require('fs');

//Syncvar data=fs.readFileSync('data.txt',{encoding:'utf8'});console.log(data);

//Asyncfs.readFile('data.txt',{encoding:'utf8'}, function(err,data){console.log(data);

})

Page 9: Node.js 기본과정

2주차 첫번째 스터디 ­ Node.js

sync�vs.�asyncvar fs=require('fs');

//Syncconsole.log(1);var data=fs.readFileSync('data.txt',{encoding:'utf8'});console.log(data);

//Asyncconsole.log(2);fs.readFile('data.txt',{encoding:'utf8'}, function(err,data){console.log(3);console.log(data);

})console.log(4);

Page 10: Node.js 기본과정

2주차 첫번째 스터디 ­ Node.js

서버 구동- const /�var

- module�export

- object(객체)

- method,�property

- argument

- call-back�function

- request,�response

Page 11: Node.js 기본과정

2주차 첫번째 스터디 ­ Node.js

express

RUBY

Ruby�on�Rails

Node.js

Express

Page 12: Node.js 기본과정

2주차 첫번째 스터디 ­ Node.js

express�module

//Routing forthehometabapp.get('/', function(req,res){res.render('index');

});

//Exportingexpressmodulevar express=require('express');var app=express();

Page 13: Node.js 기본과정

2주차 첫번째 스터디 ­ Node.js

mysql module//Exportingmysql modulevarmysql =require('mysql');

//Mysql connectionvar client=mysql.createConnection({host:'localhost',user:'root',password:‘12345678’,database:'dontmiss'

});

Page 14: Node.js 기본과정

2주차 첫번째 스터디 ­ Node.js

jade�/�ejs / angular템플릿엔진

body-parserBody로 넘어오는값 가져올때

특히 POST method 쓸 때사용함

Page 15: Node.js 기본과정

2주차 첫번째 스터디 ­ Node.js

Get�/�Post//Routing forthe1sttabapp.get('/newsfeed', function(req,res){//SelectQueryclient.query('SELECT*FROMschedule', function(err,results){if(err){console.log(err);

}res.render('newsfeed', {results:results});

});});

//Routing forthe2nd tab- postapp.post('/myfeed', function(req,res){vardata={'title':req.body.title,'description':

req.body.description};

//InsertQueryclient.query('INSERTINTOscheduleset?',data,function(err

result){if(err){console.error(err);throwerr;

}res.send(200, 'POSTSuccess!');

});});

Page 16: Node.js 기본과정

이후에 공부할 내용1. 서버셋팅AWS EC2Nodejs install Gabia DNS server setting - Ordernow.co.krRoute53 - url setting ?Ngnix

2. 클라이언트작업ejs module 5 tabs - Newsfeed, pg&md list, upload, chatting, my list

3. 디비설계/구축AWS RDS - ec2에연동Mysql module Db생성 - User(username, password, email, img_user, description, pg_yes, md_yes) Photo(user_id, uploaded_datetime, url)

4. 회원가입/로그인Passport module Sign up, log in(가능하면페북로그인)

5. 이미지업로드Upload 탭AWS S3 Body-parser module 이미지업로드(post) - 파일첨부, 컨셉, 장소

6. 이미지뿌려주기Newsfeed에서뿌려주기(각카드마다유저네임, 유저이미지, 사진, 컨셉, 장소, 업로드시간) Mylist(각카드마다사진, 컨셉, 장소, 업로드시간)

7. 모델/사진가로등록하기Mylistpost로타입선택해서할수있도록등록Db-md, pg(user_id, description, price, img_pf1) md or pg 등록하는기능Pg&md list에서뿌려주기Newsfeed에서 pf에대한정보정리해서뿌려주기

8.채팅Chatting탭Db-chat생성하고대화내용저장 – mongooseSocket.io

Page 17: Node.js 기본과정

이후에 공부할 내용1. 서버셋팅AWS EC2Nodejs install Gabia DNS server setting - Ordernow.co.krRoute53 - url setting ?Ngnix

2. 클라이언트작업ejs module 5 tabs - Newsfeed, pg&md list, upload, chatting, my list

3. 디비설계/구축AWS RDS - ec2에연동Mysql module Db생성 - User(username, password, email, img_user, description, pg_yes, md_yes) Photo(user_id, uploaded_datetime, url)

4. 회원가입/로그인Passport module Sign up, log in(가능하면페북로그인)

5. 이미지업로드Upload 탭AWS S3 Body-parser module 이미지업로드(post) - 파일첨부, 컨셉, 장소

6. 이미지뿌려주기Newsfeed에서뿌려주기(각카드마다유저네임, 유저이미지, 사진, 컨셉, 장소, 업로드시간) Mylist(각카드마다사진, 컨셉, 장소, 업로드시간)

7. 모델/사진가로등록하기Mylistpost로타입선택해서할수있도록등록Db-md, pg(user_id, description, price, img_pf1) md or pg 등록하는기능Pg&md list에서뿌려주기Newsfeed에서 pf에대한정보정리해서뿌려주기

8.채팅Chatting탭Db-chat생성하고대화내용저장 – mongooseSocket.io

Page 18: Node.js 기본과정

Node.js 프로젝트

신촌 크레바스 스터디 - 2주차 두번째

홍석유[email protected]

Page 19: Node.js 기본과정

이후에 공부할 내용1. 서버셋팅AWS EC2Nodejs install Gabia DNS server setting - Ordernow.co.krRoute53 - url setting ?Ngnix

2. 클라이언트작업ejs module 5 tabs - Newsfeed, pg&md list, upload, chatting, my list

3. 디비설계/구축AWS RDS - ec2에연동Mysql module Db생성 - User(username, password, email, img_user, description, pg_yes, md_yes) Photo(user_id, uploaded_datetime, url)

4. 회원가입/로그인Passport module Sign up, log in(가능하면페북로그인)

5. 이미지업로드Upload 탭AWS S3 Body-parser module 이미지업로드(post) - 파일첨부, 컨셉, 장소

6. 이미지뿌려주기Newsfeed에서뿌려주기(각카드마다유저네임, 유저이미지, 사진, 컨셉, 장소, 업로드시간) Mylist(각카드마다사진, 컨셉, 장소, 업로드시간)

7. 모델/사진가로등록하기Mylistpost로타입선택해서할수있도록등록Db-md, pg(user_id, description, price, img_pf1) md or pg 등록하는기능Pg&md list에서뿌려주기Newsfeed에서 pf에대한정보정리해서뿌려주기

8.채팅Chatting탭Db-chat생성하고대화내용저장 – mongooseSocket.io

Page 20: Node.js 기본과정

이후에 공부할 내용1. 서버셋팅AWS EC2Nodejs install Gabia DNS server setting - Ordernow.co.krRoute53 - url setting ?Ngnix

2. 클라이언트작업ejs module 5 tabs - Newsfeed, model_list, chatting, my_page

3. 디비설계/구축AWS RDS - ec2에연동Mysql module Db생성 - User(username, password, email, img_user, description, pg_yes, md_yes) Photo(user_id, uploaded_datetime, url)

4. 회원가입/로그인Passport module Sign up, log in(가능하면페북로그인)

5. 이미지업로드Upload 탭AWS S3 Body-parser module 이미지업로드(post) - 파일첨부, 컨셉, 장소

6. 이미지뿌려주기Newsfeed에서뿌려주기(각카드마다유저네임, 유저이미지, 사진, 컨셉, 장소, 업로드시간) Mylist(각카드마다사진, 컨셉, 장소, 업로드시간)

7. 모델/사진가로등록하기Mylistpost로타입선택해서할수있도록등록Db-md, pg(user_id, description, price, img_pf1) md or pg 등록하는기능Pg&md list에서뿌려주기Newsfeed에서 pf에대한정보정리해서뿌려주기

8.채팅Chatting탭Db-chat생성하고대화내용저장 – mongooseSocket.io

Page 21: Node.js 기본과정

이후에 공부할 내용1. 서버셋팅AWS EC2Nodejs install Gabia DNS server setting - Ordernow.co.krRoute53 - url setting ?Ngnix

2. 클라이언트작업ejs module 4 tabs - Newsfeed, pg&md list, chatting, my list

3. 디비설계/구축AWS RDS - ec2에연동Mysql module Db생성 - User(username, password, email, img_user, description, pg_yes, md_yes) Photo(user_id, uploaded_datetime, url)

4. 회원가입/로그인Passport module Sign up, log in(가능하면페북로그인)

Nginx가 필요한가?

Ejs vs.�Jade(Pug)

Mysql vs.�MariaDB

Page 22: Node.js 기본과정

2주차 첫번째 스터디 ­ Node.js

Nginx

LAMP의 Apache와 같은

웹서버

캐시, 프록시서버로드밸런싱까지알아서?

리버스 프록시 서버.

Page 23: Node.js 기본과정

2주차 첫번째 스터디 ­ Node.js

파일구조

Page 24: Node.js 기본과정

2주차 첫번째 스터디 ­ Node.js

ordernow.co.kr

Page 25: Node.js 기본과정

API

신촌 크레바스 스터디 - 2주차 세번째

홍석유[email protected]

Page 26: Node.js 기본과정

2주차 세번째 스터디 ­ Node.js

Rest�API

WWW의Software�Architecture�Style

REpresentational StateTransfer

출처: 위키피디아

자원을정의하고자원에대한주소를지정하는방법

Page 27: Node.js 기본과정

2주차 세번째 스터디 ­ Node.js

Rest�APIResource,�Method,�Message(URI)

이름이 ‘terry’인 사용자를생성한다.

HTTP Post, http://myweb/users/{

“name“:“terry“}

유저: /users

URI�패턴: /users/{user}

Page 28: Node.js 기본과정

2주차 세번째 스터디 ­ Node.js

리소스

2.�리소스 정의 = 설계의 역할

1.리소스는복수(plural)

Users�vs. Models

users,�books

/api/v1/users?type=model /api/v1/models

Page 29: Node.js 기본과정

2주차 세번째 스터디 ­ Node.js

메소드Post,�Put,�Get,�Delete

Create,Read,Update,Delete

Resource,�Method,�Message(URI)

이름이 ‘terry’인 사용자를생성한다.

HTTP get, http://myweb/users/terry

http://myweb/users 라는 사용자 리소스 중에, id가 terry 인 사용자 정보에 대해서, 주소를 “suwon”으로 수정

HTTP Post, http://myweb/users/{

“name“:“terry“}

Page 30: Node.js 기본과정

2주차 세번째 스터디 ­ Node.js

URI�버전닝1. /api/v1/users

2. request�header

3. content�type

출처: https://www.troyhunt.com/your-api-versioning-is-wrong-which-is/

Page 31: Node.js 기본과정

2주차 세번째 스터디 ­ Node.js

실제사례

Page 32: Node.js 기본과정

2주차 세번째 스터디 ­ Node.js

실제사례

ordernow.co.kr/api/v1/books

Page 33: Node.js 기본과정

2주차 세번째 스터디 ­ Node.js

postman

Page 34: Node.js 기본과정

2주차 세번째 스터디 ­ Node.js

아쉬운점var apiRoutes =�express.Router();