Node.js + Express + MongoDB

1,592 views
1,336 views

Published on

Node.js + Express + MongoDB 를 활용한 웹애플리케이션 개발

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,592
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
14
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Node.js + Express + MongoDB

  1. 1. Node.js + Express + MongoDB 를 활용한 웹애플리케이션 개발 2013.3.18 티몬 웹개발유닛 박상국
  2. 2. Node.js• Server-side (익숙한) Javascript• is not Library or Framework• But Google 자바스크립트 엔진 v8• Purely Evented• Non-blocking(비동기) I/O• Event Loop & Callback Pattern• Npm (Nodejs Package Manager)
  3. 3. Apache vs Nginx
  4. 4. Event Loop그 동안 우리는 : puts("Enter your name: "); var name = gets(); puts("Name: " + name);앞으로 우리는 : puts("Enter your name: "); gets(function(name) { puts("Name: " + name); });
  5. 5. Example
  6. 6. Express• Node.js 용 MVC Framework• 고성능, 고품격(?) 웹app 개발• 강력한 라우팅• Restful• 쉬운 기능확장• 템플릿 엔진 Jade
  7. 7. Express 구조• node_modules 추가 확장 모듈이 저장되는 곳• public 이미지, js, css 등의 미디어 파일을 저장한다• routes 데이터 엑세스 및 서버사이드 작업 라우팅 (Controller)• Views html 등의 템플릿 뷰. Jade 등의 템플릿엔진 사용 (View)• app.js main 실행 파일• package.json 패키지 설정
  8. 8. JadeNode Template Engine doctype 5 <!DOCTYPE html> html(lang="en") <html lang="en"> head <head> title= pageTitle <title>Jade</title> <script type="text/javascript"> script(type=text/javascript) if (foo) { if (foo) { bar() bar() } } </script> body </head> h1 Jade - node template engine <body> <h1>Jade - node template engine</h1> #container <div id="container"> if youAreUsingJade <p>You are amazing</p> p You are amazing </div> else </body> p Get on it! </html>
  9. 9. Express 시작하기$ express test$ cd test && npm install -끝-
  10. 10. Example
  11. 11. MongoDB• NoSQL 계의 김연아• 대용량을 지향하는 문서기반의 데이터구조• 기존 RDBMS 대비 월등한 속도 & 퍼포먼스• (익숙한) Json 기반의 데이터• No Schema – 관계성을 포기하고 확장성을 선택• SQL Syntax 에 그나마 가장 근접• Auto-sharding (아직은 미흡)• Mongoose
  12. 12. SQL vs MongoDBSQL Terms/Concepts MongoDB Terms/Conceptsdatabase databasetable collectionrow document or BSON documentcolumn fieldprimary key primary keySpecify any unique column or column co In MongoDB, the primary key is automambination as primary key. tically set to the _id field.CREATE TABLE users ( id MEDIUMINT NOT NULL db.users.insert( { AUTO_INCREMENT, user_id: "abc123", user_id Varchar(30), age: 55, age Number, status: "A" status char(1), }) PRIMARY KEY (id))
  13. 13. SQL Terms/Concepts MongoDB Terms/Concepts db.users.insert( {INSERT INTO users(user_id, age, status) user_id: "bcd001", age: 45, status: "A"VALUES ("bcd001", 45, "A") })SELECT * db.users.find()FROM usersSELECT * FROM users db.users.find({ status: "A" })WHERE status = "A" db.users.find( { status: "A“, status: { $ne: “B" },SELECT user_id, status FROM users age: { $gt: 25, $lte: 50 },WHERE status = "A“ AND status != “B“ user_id: /bc/AND age > 25 AND age <= 50 },AND user_id like "%bc%" { user_id: 1, status: 1, _id: 0 } )SELECT * FROM users db.users.find( { status: "A" } ).sort( { user_id: -WHERE status = "A" 1})ORDER BY user_id DESCSELECT COUNT(*)FROM users db.users.count( { age: { $gt: 30 } } )WHERE age > 30SELECT * db.users.findOne()FROM users orLIMIT 1 db.users.find().limit(1)
  14. 14. Example

×