1 Express + MongoDB Express MongoDB Express MongoDB Node.js Express MongoDB Express Express Node.js Web Web Ex

Similar documents
WebSphere Studio Application Developer IBM Portal Toolkit... 2/21 1. WebSphere Portal Portal WebSphere Application Server stopserver.bat -configfile..

Junos Pulse Mobile Security R1 2012, Juniper Networks, Inc.

epub 61-2

本 课 程 作 为 非 计 算 机 专 业 本 科 通 识 课 程, 是 一 门 理 论 和 实 践 紧 密 结 合 的 实 用 课 程, 内 容 包 括 计 算 机 基 础 部 分 和 程 序 设 计 部 分 计 算 机 基 础 部 分 涵 盖 计 算 机 软 硬 件 组 成 数 制 表 示 操

ebook140-9

Symantec™ Sygate Enterprise Protection 防护代理安装使用指南

<ADB6ADB1C25EA8FAA6DB2D4D56432E706466>

IP505SM_manual_cn.doc

IBM Rational ClearQuest Client for Eclipse 1/ IBM Rational ClearQuest Client for Ecl

ii Vue Bootstrap 4 ES 6 Vue Vue Bootstrap 4 ES 6 Vue 2 vue html vue html vue Vue HTML 5 CSS ES 6 HTML 5 CSS Visual Studio Code h

AL-M200 Series

關於本書 l 3 PhoneGap Appcelerator Titanium Sencha Touch (wrapper framework) Native App PhoneGap Build Native App Hybrid App Java Objective-C Android SDK

GoFlex Home UG Book.book

untitled

Node.js LinkedIn Yahoo! Netflix JavaScript JavaScript Node.js Node.js JavaScript JavaScript Node.js Ruby C++ Java PHP JavaScript Node.js Node PHP Apac

5-1 nav css 5-2

Adobe AIR 安全性

ebook

Microsoft Word - template.doc

untitled

vi JSON JSON API XML JSON JSON JavaScript RESTful JSON Douglas Crockford JSON / RESTful API JavaScript Node.js Ruby on Rails Java Groovy

Microsoft Word zw

chapter 2 HTML5 目錄iii HTML HTML HTML HTML HTML canvas

投影片 1

1. 2. Flex Adobe 3.

SL2511 SR Plus 操作手冊_單面.doc

AL-MX200 Series

Azure_s

基于UML建模的管理管理信息系统项目案例导航——VB篇

關於本書 Part 3 CSS XHTML Ajax Part 4 HTML 5 API JavaScript HTML 5 API Canvas API ( ) Video/Audio API ( ) Drag and Drop API ( ) Geolocation API ( ) Part 5

目 錄 第 一 章 weberp 簡 介... 6 第 一 節 概 述... 6 第 二 節 安 全 性... 7 第 三 節 功 能... 7 一 銷 售 及 訂 單... 7 二 稅... 8 三 應 收 帳 款... 8 四 存 貨... 8 五 購 買... 9 六 應 付 帳 款... 9

Microsoft Word - WebGoat用户指南-beta2.doc

中国软件2013校园招聘通知

软件概述

Sophos Central 快速安裝手冊

1 SQL Server 2005 SQL Server Microsoft Windows Server 2003NTFS NTFS SQL Server 2000 Randy Dyess DBA SQL Server SQL Server DBA SQL Server SQL Se

计算机软件技术专业教学计划

A9RF716.tmp

目 录 简 介.3 ` 体 系 结 构...4 数 据 层...5 数 据 连 接 器...6 Tableau Server 组 件...7 网 关 / 负 载 平 衡 器...8 客 户 端 :Web 浏 览 器 和 移 动 应 用 程 序...8 客 户 端 :Tableau Desktop..

RUN_PC連載_10_.doc


Windows RTEMS 1 Danilliu MMI TCP/IP QEMU i386 QEMU ARM POWERPC i386 IPC PC104 uc/os-ii uc/os MMI TCP/IP i386 PORT Linux ecos Linux ecos ecos eco

XXXXXXXX

Fiery Command WorkStation

Microsoft Word - Functional_Notes_3.90_CN.doc

目录

的 開 銷, 請 務 必 先 和 家 裡 討 論 後 再 做 決 定 二 研 修 學 校 簡 介 卡 內 基 美 隆 大 學 (Carnegie Mellon University), 位 於 賓 州 匹 茲 堡 會 選 擇 來 這 裡 交 換, 我 相 信 大 部 分 的 人 都 已 經 知 道

IC-900W Wireless Pan & Tilt Wireless Pan & Tilt Remote Control / Night Vision FCC ID:RUJ-LR802UWG

x 前言 Python Python ETL extract transform load Python Python / Python Python Python

ARM JTAG实时仿真器安装使用指南

Microsoft Word - PS2_linux_guide_cn.doc

RunPC2_.doc

Serial ATA ( Silicon Image SiI3114)...2 (1) SATA... 2 (2) B I O S S A T A... 3 (3) RAID BIOS RAID... 5 (4) S A T A... 8 (5) S A T A... 10

Guide to Install SATA Hard Disks

RUN_PC連載_8_.doc

PowerPoint Presentation

资源管理软件TORQUE与作业调度软件Maui的安装、设置及使用

UDC The Design and Implementation of a Specialized Search Engine Based on Robot Technology 厦门大学博硕士论文摘要库

epub83-1

声 明 本 公 司 及 全 体 董 事 监 事 高 级 管 理 人 员 承 诺 不 存 在 任 何 虚 假 记 载 误 导 性 陈 述 或 重 大 遗 漏, 并 对 其 真 实 性 准 确 性 完 整 性 承 担 个 别 和 连 带 的 法 律 责 任 本 公 司 负 责 人 和 主 管 会 计 工

PowerPoint 演示文稿

ebook140-8

可 Web 编程的NativeUI 设计与实现

2005 3

p.2 1 <HTML> 2 3 <HEAD> 4 <TITLE> </TITLE> 5 </HEAD> 6 7 <BODY> 8 <H3><B> </B></H3> 9 <H4><I> </I></H4> 10 </BODY> </HTML> 1. HTML 1. 2.

final

目 录 目 录 平 台 概 述 技 术 架 构 技 术 特 点 基 于 统 一 平 台 的 多 产 品 线 支 撑 先 进 性 安 全 性 开 放 性 高 性 能 和

Network Bandwidth Applications MATE Applications Applications On Demand Calendaring Load Balancer Live Archive Design Northbound Service,Netwo

FileMaker 15 WebDirect 指南

基于CDIO一体化理念的课程教学大纲设计

1

软件测试(TA07)第一学期考试

Olav Lundström MicroSCADA Pro Marketing & Sales 2005 ABB - 1-1MRS755673

<4D F736F F F696E74202D20C8EDBCFEB2E2CAD4D1A7CFB0D7CAC1CF2E BBCE6C8DDC4A3CABD5D>

0SQL SQL SQL SQL SQL 3 SQL DBMS Oracle DBMS DBMS DBMS DBMS RDBMS R DBMS 2 DBMS RDBMS R SQL SQL SQL SQL SELECT au_fname,au_ lname FROM authors ORDER BY

29 知 識 管 理 c.1 1 樓 新 到 館 圖 書 區 30 知 識 管 理 c.2 1 樓 新 到 館 圖 書 區 31 編 劇 與 腳 本 設 計


投影片 1

目 录 1. 前 言 为 什 么 要 用 ESB 技 术 发 展 业 务 需 求 IT 需 求 IT 与 业 务 一 致 性 要 求 TongIntegrator ESB v5 简 介..

ASP.NET MVC Visual Studio MVC MVC 範例 1-1 建立第一個 MVC 專案 Visual Studio MVC step 01 Visual Studio Web ASP.NET Web (.NET Framework) step 02 C:\M

AXIS P7224 Video Encoder Blade – Installation Guide

1 IT IT IT IT Virtual Machine, VM VM VM VM Operating Systems, OS IT

Cadence Poqi

1 1 大概思路 创建 WebAPI 创建 CrossMainController 并编写 Nuget 安装 microsoft.aspnet.webapi.cors 跨域设置路由 编写 Jquery EasyUI 界面 运行效果 2 创建 WebAPI 创建 WebAPI, 新建 -> 项目 ->

Transcription:

1 Express + MongoDB Express MongoDB Express MongoDB 1.1 1.1.1 Node.js 0.10.32 Express 4.10.2 MongoDB 2.6.1 1.1.2 1. Express Express Node.js Web Web Express $ npm install -g express-generator Express Express 2. Windows Linux Mac blog 001

1.1 Express ejs 3. blog 1-3 1-3 blog app.js package.json dependencies npm install npm package. json node_modules package.json package.json public image css js routes views bin app.js var express = require('express'); var path = require('path'); var favicon = require('serve-favicon'); var logger = require('morgan'); varcookieparser = require('cookie-parser'); varbodyparser = require('body-parser'); var routes = require('./routes/index'); var users = require('./routes/users'); var app = express(); // view engine setup app.set('views', path.join( dirname, 'views')); app.set('view engine', 'ejs'); 003

1.4 1.4 /u/ /u/ / / post.js Post.get Post.getAll index.js Post.get Post.getAll post.js // Post.getOne = function(name, day, title, callback) { // mongodb.open(function (err, db) { if (err) { return callback(err); } // posts db.collection('posts', function (err, collection) { if (err) { mongodb.close(); return callback(err); } // collection.findone({ "name": name, "time.day": day, "title": title }, function (err, doc) { mongodb.close(); if (err) { return callback(err); } // markdown html doc.post = markdown.tohtml(doc.post); callback(null, doc);// }); }); }); }; Post.getAll name Post.getOne 045

1.4 article.ejs views user.ejs index.ejs <%- include header %> <% posts.foreach(function (post, index) { %> <p><h2><a href="/u/<%= post.name %>/<%= post.time.day %>/<%= post.title %>"><%= post.title %></a></h2></p> <p class="info"> <a href="/u/<%= post.name %>"><%= post.name %></a> <%= post.time.minute %> </p> <p><%- post.post %></p> <% }) %> <%- include footer %> views article.ejs <%- include header %> <p class="info"> <a href="/u/<%= post.name %>"><%= post.name %></a> <%= post.time.minute %> </p> <p><%- post.post %></p> <%- include footer %> 1-27 1-27 047

2 Express + MongoDB 1 Express + MongoDB 7 2.1 Passport oauth/oauth2.0 oauth oauth oauth oauth Passport Passport Node.js Passport Express Web 085

第 2 章 使用 Express + MongoDB 搭建多人部落格番外篇 現在我們來修改程式碼 使得我們的部落格既支援本地登錄又支援使用 GitHub 帳 戶登錄 首先 登錄 GitHub 按一下右上角的 Account settings 然後按一下左側 的 Applications 然 後 按 一 下 右 上 角 的 Register new application 建 立 一 個 GitHub 應用 建立成功後如圖 2-1 所示 圖 2-1 建立一個 GitHub 應用 稍後我們將會用到 Client ID Client Secret 和 Authorization callback URL 打開 package.json 新增 passport 和 passport-github 模組 "passport": *", passport-github": *" 並執行 npm install 安裝這兩個模組 至此 準備工作都已完成 接下來我們修 改程式碼支援使用 GitHub 帳戶登錄 首先 新增使用 GitHub 登錄的連結 打開 login.ejs 在 <%- include footer %> 上一行新增如下程式碼 <a href="/login/github"> 使用 GitHub 登錄 </a> 然後打開 app.js 在 var app = express(); 下方新增如下程式碼 var passport = require('passport'), GithubStrategy = require('passport-github').strategy; 086

2.2 Heroku 2-2 2-2 Mongo URL MongoHQ Admin Users username password db.adduser('username','password') Add user settings.js module.exports = { cookiesecret: 'myblog', url: 'your_mongo_uri' }; your_mongo_uri URL <user> <password> app.js app.use(express.session(...)); app.use(express.session({ secret: settings.cookiesecret, cookie: {maxage: 1000 * 60 * 60 * 24 * 30},//30 days url: settings.url })); db.js post.js user.js comment.js mongodb = require('./db') mongodb=require('mongodb').db varsettings=require('../settings'); mongodb.open(function(err, db){ mongodb.connect(settings. url, function (err, db) { 089

2 Express + MongoDB mongodb.close(); db.close(); Heroku MongoHQ Add-ons MongoHQ 2. Heroku Heroku PaaS Git Git Ruby Heroku Node.js Clojure Scala Python Java Heroku Heroku (1) https:// www.heroku.com/ (2) 2-3 2-3 Create a new app Creat app Finish up 090

4 Meteor Node.js Meteor Meteor 4.1 Meteor 1. Meteor Meteor Node.js+Websocket+MongoDB Web Meteor JavaScript Rich Web Meteor Meteor 2. Meteor (1) HTML (2) JavaScript (3) API (4) (5) 139

4 Meteor (6) Meteor (7) Meteor API 4.2 Meteor Meteor 0.6.6.3 Mac Linux Mac OS X 10.6 and above Linux x86 and x86_64 systems Windows Meteor Windows Meteor http://win. meteor.com 1. Meteor Windows Mac Linux Meteor $ curl https://install.meteor.com /bin/sh 2. $ meteor create myapp Meteor myapp myapp.js myapp.html myapp.css.meteor Windows Meteor Meteor meteor.bat 3. Meteor Meteor $ cd myapp $ meteor => Meteor server running on: http://localhost:3000/ localhost:3000 4-1 140

4 Meteor deploy Deploy this project to Meteor logs Show logs for specified site reset Reset the project state. Erases the local database. test-packages Test one or more packages See 'meteor help <command>' for details on a command. 4. Meteor Meteor Meteor Node.js Node.js Meteor Meteor 1.0 Meteor API Meteor meteor list accounts-base A user account system accounts-password Password support for accounts. autopublish Automatically publish the entire database to all backbone A minimalist client-side MVC framework bootstrap Front-end framework from Twitter coffeescript Javascript dialect with fewer braces and semicolons d3 Library for manipulating documents based on data. email Send email messages handlebars Simple semantic templating language http Make HTTP calls to remote servers insecure Allow all database writes by default jquery Manipulate the DOM using CSS selectors less The dynamic stylesheet language. preserve-inputs Automatically preserve all form fields with a unique id showdown Markdown-to-HTML processor spiderable Makes the application crawlable to web spiders. stylus Expressive, dynamic, robust CSS. underscore Collection of small helper functions: _.map, _.each,... 4.3 leaderboard Meteor Meteor examples https://github.com/ meteor/meteor/tree/devel/examples/leaderboard leaderboard leaderboard $ meteor 4-2 142

4.3 4-2 meteor player 6 Give 5 points 5 leaderboard leaderboard 1.meteor leaderboard.js leaderboard. css leaderboard. html Meteor 1.meteor Meteor 1 MongoDB Meteor API leaderboard.css body { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight: 200; margin: 50px 0; padding: 0; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -o-user-select: none; user-select: none; } #outer { 143