Node.js 팀 스터디 발표자료.

15
황급히 배워보는 Node.js 2012.09.25 [email protected]

description

2012년 9월 Node.js 팀 스터디 발표자료.

Transcript of Node.js 팀 스터디 발표자료.

Page 1: Node.js 팀 스터디 발표자료.

황급히����������� ������������������  배워보는����������� ������������������  Node.js

2012.09.25 [email protected]

Page 2: Node.js 팀 스터디 발표자료.

What is Node.js

Created by Ryan Dahl starting in 2009.02 (personal project)

JavaScript Runtime on V8 JavaScript engine (Google Chrome Web browser) based

Server Side JavaScript

implements some CommonJS (JavaScript: not just for browsers any more!) standard spec like Couch DB, RingoJS

Single Thread(Not Multi Thread), Single Stack, Event Loop

Everything is Nonblocking I/O, But 개발자가 작성한 코드(싱글쓰레드)는 동기

Page 3: Node.js 팀 스터디 발표자료.

History

2009.02.09 Ryan posted “Event driven TCP library & HTTP Server on chrome web browser’s V8 engine” idea. inspiration from (CouchDB, Ebb, Flow, FUSE, libebb, libeio, libev, libircclient, Merb, Mongrel, NGINX, nginx-ey-balancer, Ragel, Ruby on Rails, SqueezeBox, timber lang, XUpload)

2009.02.15 created GitHub repository

2009.11.07 v0.1.16 in JSConf.eu

2012.09.20 v0.8.9 14,919 NPM packages

Page 4: Node.js 팀 스터디 발표자료.

Advantages* 동시 접속 수에 따른 초당 요청 처리 수가 멀티쓰레딩에 비해 월등함.

100명의 동접자, 1메가 바이트 응답

node 822 req/sec

nginx 708 req/sec

thin 85 req/sec

mongrel 4 req/sec

* 2012년 9월 현재 14,919 개의 Package가 존재, 개발이 용이

* JavaScript

Page 5: Node.js 팀 스터디 발표자료.

Disadvantages

CPU 개수, Memory 용량을 높여도 성능이 크게 향상되지 않는다. (노드 인스턴스를 여러 개 실행함으로써 해결 가능)

짧은 역사로 인해 다양한 상황에서의 검증이 이뤄지지 않음

callback style 구현의 어려움

Page 6: Node.js 팀 스터디 발표자료.

blocking / nonblocking* blocking (동기)

puts(“이름을 입력하세요”);var name = gets();puts(“당신의 이름은 “ + name + “입니다.”);

puts(“next work.”);

* nonblocking (비동기)puts(“이름을 입력하세요”);gets(function(name) { puts(“당신의 이름은 “ + name + “입니다.”);});

puts(“next work.”);

Page 7: Node.js 팀 스터디 발표자료.

Coding convention* 들여쓰기 들여쓰기는 공백 2칸으로 한다.* 세미콜론 세미콜론은 항상 사용한다.* 작은따옴표 문자열 등은 큰 따옴표 대신 작은따옴표를 사용한다.* 중괄호 다음과 같이 작성한다.

if (true) { //내용

}* 변수 소문자로 시작하는 카멜케이스(camel case) 사용* 클래스 대문자로 시작하는 카멜케이스 사용* 상수 모두 대문자 * 동등비교 == 대신 ===를 사용한다.* 콜백함수 콜백함수에서 첫 파라미터는 에러 파라미터로 사용한다. callback(err, param1, param2)

Page 8: Node.js 팀 스터디 발표자료.

ex) simple web server

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/');

Page 9: Node.js 팀 스터디 발표자료.

ex) tcp server

var net = require('net');

var server = net.createServer(function (socket) { socket.write('Echo server\r\n'); socket.pipe(socket);});

server.listen(1337, '127.0.0.1');

Page 10: Node.js 팀 스터디 발표자료.

ex) File Systemvar fs = require('fs');

fs.readFile(‘./test.txt’, encoding=‘utf-8’, function(err, data) { if (err) { throw err; } console.log(data);});

console.log(‘파일의 내용 : ’);

//infinite loopwhile(true) {}

//safe setTimeout(function() { console.log("5 secs timeout");}, 5000);

Page 11: Node.js 팀 스터디 발표자료.

Node.js스러운����������� ������������������  코드����������� ������������������  작성법

The Node Beginner Bookhttp://www.nodebeginner.org/index-kr.html

Page 12: Node.js 팀 스터디 발표자료.

npm (node package manager)

* global install npm install 패키지명 -g

* local install npm install 패키지명

* uninstall npm uninstall 패키지명

* update npm update

* search npm search 검색어

Page 13: Node.js 팀 스터디 발표자료.

Packages to Try

express - web framework

socket.io - realtime networking

persist - ORM framework

async - async helpers

db-migrate - database migrations

VOWS - BDD framework

dnode - RPC

java - bridge to Java API

Page 14: Node.js 팀 스터디 발표자료.

Service using node.js

LinkedIn (http://www.linkedin.com)

Trello (http://trello.com) express + socket.io

Yammer (http://www.yammer.com) private social network

Cloud9 IDE (http://c9.io) Node.js + Socket.io

네이버 개발자 노트 (http://github.com/nforge/devnote) 마크다운 기반위키프로젝트 프로젝트 빌드/테스트 ServerSide/Front-end 모두 자바스크립트로만 작성

Page 15: Node.js 팀 스터디 발표자료.

End