node and express configuration

11
NODE…AND EXPRESS

Upload: jiseob-kim

Post on 16-Jan-2017

229 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Node and Express Configuration

NODE…AND EXPRESS

Page 2: Node and Express Configuration

기본 설정• NODE 설치• https://nodejs.org/ 그냥 설치• Mongo DB 설치• https://www.mongodb.org/downloads• 그냥 download & 설치• 환경변수 설정 \bin 으로 path 설정• Mongod –dbpath 경로 ( 경로폴더 미리 만들어야 함 )• GUI TOOL : http://robomongo.org/• md \data\db• mongod

Page 3: Node and Express Configuration

Node 로 서버 생성server.js 파일 만들기

var http = require('http');http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World!\n');}).listen(1337, '127.0.0.1');console.log('Server running at http://127.0.0.1:1337/');

server.js 실행>node server.js결과

Ctrl + C 누르면 종료됨브라우저로 http://127.0.0.1:1337로 접속해서 확인하기

Page 4: Node and Express Configuration

Node Debugging 1Node inspector 설치>npm install -g node-inspector

Node inspector 실행>node-inspector

Page 5: Node and Express Configuration

Node Debugging 2server.js 파일 만들기

var http = require('http');debugger;http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); debugger; res.end('Hello World!\n');}).listen(1337, '127.0.0.1');console.log('Server running at http://127.0.0.1:1337/');server.js debug 모드로 실행>node --debug server.js

Page 6: Node and Express Configuration

Node Debugging 3

브라우저에서 http://127.0.0.1:1337 접속하여 debugging 되는지 확인

브라우저 ( 크롬 ) 에서 node inspector 로 접속 http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858

Page 7: Node and Express Configuration

Express 1Express-generator 설치

>npm install express-generator -g

>express express-sample-prjExpress 프로젝트 생성

Page 8: Node and Express Configuration

Express 2생성한 프로젝트 디렉토리로 이동

>cd express-sample-prjpackage.json 에 기술된 dependencies 설치

>npm install

스캐폴딩되어 생성된 프로젝트 실행>npm start

브라우저로 접속 (address : localhost:3000)

Page 9: Node and Express Configuration

Express 3폴더 구조

1. 시작점 www

2.app.js 에서 필요한 모듈읽기 & route, static, view 설정

3.route 별 javascript

4. 결과로 출력될 jade 파일

5. 렌더링에 필요한 resource 파일

Page 10: Node and Express Configuration

modules소스코드 변경 시 노드 서버 자동 재시작 모듈>npm install nodemon

몽고 DB 드라이버 설치>npm install mongoose --save

비밀번호 암호화 모듈>npm install bcrypt-nodejs --save

Html scrapinp 을 위한 모듈 설치>npm install request --save>npm install cheerio --save

Page 11: Node and Express Configuration

modulesUsername & password 와 jwt 인증 구현을 위한 passport 설치

>npm install passport --save>npm install passport-local –save

>npm install jwt-simple --save

기본 인증 구현을 위한 passport 설치>npm install passport --save>npm install passport-http --save

provide API HTTP Basic and Digest authentication strategies

Oauth2.0 인증을 위한 모듈>npm install passport-http-bearer --save