2. 기본 설정
• NODE 설치
• https://nodejs.org/ 그냥 설치
• Mongo DB 설치
• https://www.mongodb.org/downloads
• 그냥 download & 설치
• 환경변수 설정 bin으로 path 설정
• Mongod –dbpath 경로(경로폴더 미리 만들어야 함)
• GUI TOOL : http://robomongo.org/
• md datadb
• mongod
3. 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로 접속해서 확인하기
4. Node Debugging 1
Node inspector 설치
>npm install -g node-inspector
Node inspector 실행
>node-inspector
5. Node Debugging 2
server.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
6. 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
8. Express 2
생성한 프로젝트 디렉토리로 이동
>cd express-sample-prj
package.json에 기술된 dependencies 설치
>npm install
스캐폴딩되어 생성된 프로젝트 실행
>npm start
브라우저로 접속 (address : localhost:3000)
9. Express 3
폴더 구조
1.시작점 www
2.app.js에서 필요한 모듈읽기& route, static, view 설정
3.route별 javascript
4.결과로 출력될 jade 파일
5.렌더링에 필요한 resource 파일
10. modules
소스코드 변경 시 노드 서버 자동 재시작 모듈
>npm install nodemon
몽고DB드라이버 설치
>npm install mongoose --save
비밀번호 암호화 모듈
>npm install bcrypt-nodejs --save
Html scrapinp을 위한 모듈 설치
>npm install request --save
>npm install cheerio --save
11. modules
Username & 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