際際滷

際際滷Share a Scribd company logo
Web.js Node.js 〃 Node.js  Web.js and
Web.js Node.js JavaScript on Server-side http://nodejs.org/
Web.js Node.js E vent A sync N onBlocking
Web.js Node.js 念 極断指誅袖営蠶穽匈中議扮昨咀葎光嶽圻咀聞匈中 Block 廖議秤尚杏 壅指誅 Ajax 匯岷壓吉棋捲暦匂議指基徽頁咀葎捲暦匂融隼航渠遇聞欺屎壓聞喘嶄議匈中短嗤販採強恬議秤尚杏
Web.js Node.js
Web.js Node.js var  http = require( 'http' ), fs = require( 'fs' ), url = require( 'url' ); var  server = http. createServer (function ( req ,  res ) { var  filePath = url. parse (req. url ). pathName ; fs. readFile (filePath, function ( err ,  data ) { res. writeHead ( 200 , { 'Content-type' :  'text/plain' }); res. write ( data ); res. end (); }); }); server. listen ( 8888 );
Web.js Node.js http://expressjs.com/
Web.js Node.js var  express   = require( 'express' ), app = express. createServer (); app. configure (function(){ app. use (express. static ( __dirname )); }); app. listen ( 8888 );
Web.js Node.js /:Web.js http://web.jit.im/
Web.js Node.js require( 'webjs' ). run ()
Web.js Node.js { 堀業 痩試業 酒叟業
Web.js Node.js } 惹否來 ! 糧協來 ! 珊圻來 !
Web.js 辛參用宣 NPM(Node.js package manager) 芦廾 Web.js 音俶勣旋喘園咎匂序佩園咎辛參岷俊鹸崙欺哘喘朕村聞喘。 Express 俶勣旋喘 NPM 距喘 C++ 園咎匂序佩園咎遇拝 C++ 何蛍旺音頁來嬬恂單晒遇峪頁葎阻伏撹匯倖 CLI(command-line interface) 咀葎 Express 議囂隈鹸墫蝕窟宀壓耽匯倖哘喘蝕兵園亟議扮昨勣恂議彈姥垢恬載謹。 遇 Web.js 議囂隈掲械酒汽音俶勣湊謹議芝吮頼畠頁 JavaScript 議児粥囂隈。 Web.js Node.js
var  express = require( 'express' ), app = express. createServer (); app. get ( '/:year/:mouth/:day/:id.jpg' , function ( req ,  res ) { res. sendFile (req. params . year  +  '-'  + req. params . mouth  +  '-'  + req. params . day  +  '-'  + req. params . id  +  '.jpg' ); }); app. get ( '/:action' , function (req, res) { var  action = req. params . action ; res. send ( 'Your action is '  + action); }); Web.js Node.js
var  web = require( 'webjs' ), urlRouter = { '/:year/:mouth/:day/:id.jpg' :  '$1-$2-$3-$4.jpg' }, getRouter = { '/:action' : function ( req ,  res ) { res. send ( 'Your action is '  + req. path . action ); } }; web. run ( urlRouter ,  8888 ) . get ( getRouter ); Web.js Node.js Web.js
Web.js Node.js Request Server POST GET PostRouter PostHandler UrlRouter GetRouter Response File System Redirect GetHandler
Web.js Node.js DEMO !!  Web.js TODOS http://todos.jit.im/
Web.js Node.js Node.js + MongoDB Web.js + Mongoose
Web.js Node.js var  web = require( 'webjs' ), mongoose = require( 'mongoose' ), config = require( './config' ); var  Item =  new  mongoose. Schema ({ title:  String , status:  Number }); mongoose. model ( 'Item' ,  Item ); Item = mongoose. model ( 'Item' ); var  getRouter = { 'getItems' : function ( req ,  res ) { Item. find ({}, function ( err ,  items ) { res. sendJSON ( items ); }); } }, postRouter = { 'addItem' : function ( req ,  res ) { new  Item({ ...... }). save (function ( err ) { ...... }); }, ...... }; web. run ({},  config . www . port ) . get ( getRouter ) . post ( postRouter );
Web.js Node.js 音氏嗤陳倖 SB 議 Node.js 及眉圭庁翠蝕窟宀氏戻工揖化議 API 。 音狛 Node.js 圻伏 API 戦議鳩嗤。。 =_=
Web.js Node.js Web.js 議 API  頁畠黛議 Node.js 圻伏旗鷹辛參涙血濡卞 //Node.js 郊圭 Hello World var  http = require( 'http' ); http. createServer (function ( req ,  res ) { res. writeHead ( 200 , { 'Content-Type' :  'text/plain' }); res. end ( 'Hello World' ); }). listen ( 1337 ,  "127.0.0.1" ); //Web.js var  web = require( 'webjs' ); web. run ({},  1337 ,  '127.0.0.1' ) . get ({ '/' : function (req, res) { res. end ( 'Hello World' ); //res.send('Hello World'); } });
Web.js Node.js 艶弌心 Node.js  Node.js 匆頁 CMS 捻薦紘 貧勧猟周 var  postRouter = { 'upload' : function ( req ,  res ) { fs. writeFile ( 'somefile.txt' , //file name req. data . upload , //file data function ( err ) { //callback if ( err ) return res. send ( 'Upload failed' ); res. send ( 'Upload successed' ); }); } } * 児噐 node-formiable express 圻伏音屶隔猟周貧勧
Web.js Node.js RESTful API
Web.js Node.js
Web.js Node.js Sencha Touch + Web.js MongoDB(Mongoose) | Node.js(Web.js) | JSONP | Front End (Sencha Touch)
Web.js Node.js var  mongoose = require( "mongoose" ), ´´ web = require( "webjs" ); ´´ var  Post =  new  mongoose. Schema ({ ´´ }); ´´ var  getRouter = { "jsonData" : function (req, res) { Post. find ({}, function ( err ,  posts ) { res. sendJSON (req. qs . callback  +  '('  + JSON. stringify ( posts ) +  ')' ); }) } }; web. run ({}, config. www . port , config. www . host ) . get (getRouter); Web.js + Mongoose
Web.js Node.js Ext. apply (mmq. views , { hotMsgInnerList: new mmq. views . HotMsgInnerList ({ store : new Ext. data . Store ({ id:  'store_hm' , model:  'mmq.models.HotMsg' , autoLoad:  true , proxy : { type:  'scripttag' , url:  'http://localhost:8888/jsonData' , reader: { type:  'json' , root:  'data' }, } }) }) });
EventProxy ( 酉痩  Jackson Tian) Jscex ( 析孕  Jeffrey) Backbone (Document Cloud) Underscore (Document Cloud) Mongoose (LearnBoost) MongoSkin ( 告爽 ) ´´ Web.js Node.js Friendly Modules
Web.js Node.js Q&A

More Related Content

Node.js and Web.js

  • 1. Web.js Node.js 〃 Node.js Web.js and
  • 2. Web.js Node.js JavaScript on Server-side http://nodejs.org/
  • 3. Web.js Node.js E vent A sync N onBlocking
  • 4. Web.js Node.js 念 極断指誅袖営蠶穽匈中議扮昨咀葎光嶽圻咀聞匈中 Block 廖議秤尚杏 壅指誅 Ajax 匯岷壓吉棋捲暦匂議指基徽頁咀葎捲暦匂融隼航渠遇聞欺屎壓聞喘嶄議匈中短嗤販採強恬議秤尚杏
  • 6. Web.js Node.js var http = require( 'http' ), fs = require( 'fs' ), url = require( 'url' ); var server = http. createServer (function ( req , res ) { var filePath = url. parse (req. url ). pathName ; fs. readFile (filePath, function ( err , data ) { res. writeHead ( 200 , { 'Content-type' : 'text/plain' }); res. write ( data ); res. end (); }); }); server. listen ( 8888 );
  • 8. Web.js Node.js var express = require( 'express' ), app = express. createServer (); app. configure (function(){ app. use (express. static ( __dirname )); }); app. listen ( 8888 );
  • 9. Web.js Node.js /:Web.js http://web.jit.im/
  • 10. Web.js Node.js require( 'webjs' ). run ()
  • 11. Web.js Node.js { 堀業 痩試業 酒叟業
  • 12. Web.js Node.js } 惹否來 ! 糧協來 ! 珊圻來 !
  • 13. Web.js 辛參用宣 NPM(Node.js package manager) 芦廾 Web.js 音俶勣旋喘園咎匂序佩園咎辛參岷俊鹸崙欺哘喘朕村聞喘。 Express 俶勣旋喘 NPM 距喘 C++ 園咎匂序佩園咎遇拝 C++ 何蛍旺音頁來嬬恂單晒遇峪頁葎阻伏撹匯倖 CLI(command-line interface) 咀葎 Express 議囂隈鹸墫蝕窟宀壓耽匯倖哘喘蝕兵園亟議扮昨勣恂議彈姥垢恬載謹。 遇 Web.js 議囂隈掲械酒汽音俶勣湊謹議芝吮頼畠頁 JavaScript 議児粥囂隈。 Web.js Node.js
  • 14. var express = require( 'express' ), app = express. createServer (); app. get ( '/:year/:mouth/:day/:id.jpg' , function ( req , res ) { res. sendFile (req. params . year + '-' + req. params . mouth + '-' + req. params . day + '-' + req. params . id + '.jpg' ); }); app. get ( '/:action' , function (req, res) { var action = req. params . action ; res. send ( 'Your action is ' + action); }); Web.js Node.js
  • 15. var web = require( 'webjs' ), urlRouter = { '/:year/:mouth/:day/:id.jpg' : '$1-$2-$3-$4.jpg' }, getRouter = { '/:action' : function ( req , res ) { res. send ( 'Your action is ' + req. path . action ); } }; web. run ( urlRouter , 8888 ) . get ( getRouter ); Web.js Node.js Web.js
  • 16. Web.js Node.js Request Server POST GET PostRouter PostHandler UrlRouter GetRouter Response File System Redirect GetHandler
  • 17. Web.js Node.js DEMO !! Web.js TODOS http://todos.jit.im/
  • 18. Web.js Node.js Node.js + MongoDB Web.js + Mongoose
  • 19. Web.js Node.js var web = require( 'webjs' ), mongoose = require( 'mongoose' ), config = require( './config' ); var Item = new mongoose. Schema ({ title: String , status: Number }); mongoose. model ( 'Item' , Item ); Item = mongoose. model ( 'Item' ); var getRouter = { 'getItems' : function ( req , res ) { Item. find ({}, function ( err , items ) { res. sendJSON ( items ); }); } }, postRouter = { 'addItem' : function ( req , res ) { new Item({ ...... }). save (function ( err ) { ...... }); }, ...... }; web. run ({}, config . www . port ) . get ( getRouter ) . post ( postRouter );
  • 20. Web.js Node.js 音氏嗤陳倖 SB 議 Node.js 及眉圭庁翠蝕窟宀氏戻工揖化議 API 。 音狛 Node.js 圻伏 API 戦議鳩嗤。。 =_=
  • 21. Web.js Node.js Web.js 議 API 頁畠黛議 Node.js 圻伏旗鷹辛參涙血濡卞 //Node.js 郊圭 Hello World var http = require( 'http' ); http. createServer (function ( req , res ) { res. writeHead ( 200 , { 'Content-Type' : 'text/plain' }); res. end ( 'Hello World' ); }). listen ( 1337 , "127.0.0.1" ); //Web.js var web = require( 'webjs' ); web. run ({}, 1337 , '127.0.0.1' ) . get ({ '/' : function (req, res) { res. end ( 'Hello World' ); //res.send('Hello World'); } });
  • 22. Web.js Node.js 艶弌心 Node.js Node.js 匆頁 CMS 捻薦紘 貧勧猟周 var postRouter = { 'upload' : function ( req , res ) { fs. writeFile ( 'somefile.txt' , //file name req. data . upload , //file data function ( err ) { //callback if ( err ) return res. send ( 'Upload failed' ); res. send ( 'Upload successed' ); }); } } * 児噐 node-formiable express 圻伏音屶隔猟周貧勧
  • 25. Web.js Node.js Sencha Touch + Web.js MongoDB(Mongoose) | Node.js(Web.js) | JSONP | Front End (Sencha Touch)
  • 26. Web.js Node.js var mongoose = require( "mongoose" ), ´´ web = require( "webjs" ); ´´ var Post = new mongoose. Schema ({ ´´ }); ´´ var getRouter = { "jsonData" : function (req, res) { Post. find ({}, function ( err , posts ) { res. sendJSON (req. qs . callback + '(' + JSON. stringify ( posts ) + ')' ); }) } }; web. run ({}, config. www . port , config. www . host ) . get (getRouter); Web.js + Mongoose
  • 27. Web.js Node.js Ext. apply (mmq. views , { hotMsgInnerList: new mmq. views . HotMsgInnerList ({ store : new Ext. data . Store ({ id: 'store_hm' , model: 'mmq.models.HotMsg' , autoLoad: true , proxy : { type: 'scripttag' , url: 'http://localhost:8888/jsonData' , reader: { type: 'json' , root: 'data' }, } }) }) });
  • 28. EventProxy ( 酉痩 Jackson Tian) Jscex ( 析孕 Jeffrey) Backbone (Document Cloud) Underscore (Document Cloud) Mongoose (LearnBoost) MongoSkin ( 告爽 ) ´´ Web.js Node.js Friendly Modules