2011/01/28       node




Express

       @atakig
PHPer(CMS   )
PHPer(CMS   )
 Web
PHPer(CMS     )
 Web
    Rubyist
PHPer(CMS                       )
        Web
             Rubyist
Mac, Vim, (node.)JS, Linux, git, haskell, go
PHPer(CMS                         )
        Web
             Rubyist
Mac, Vim, (node.)JS, Linux, git, haskell, go
                , Ducati M900,      ,
node
Web
sinatra
rails
CodeIgniter
lithium
web.py
go + GAE
Express




insenely ==



              https://github.com/visionmedia/express
sinatra




http://www.sinatrarb.com/intro
http://silex.sensiolabs.org/
Express

Express
Express

Express
Mongoose
mongoDB    O/D
Express

Express
Mongoose
mongoDB    O/D


Jade
nvm
npm
      google
app.js
     package.json
     public
          images
          javascripts
          stylesheets
              style.css
     routes
          index.js
     views
        index.jade
        layout.jade
app.js

app.get('/', routes.index);
app.js
     package.json
     public
          images
          javascripts
          stylesheets
              style.css
     routes
          index.js
     views
        index.jade
        layout.jade
Model
     app.js
     package.json
     public
          images
          javascripts
          stylesheets
              style.css
     routes
          index.js
     views
        index.jade
        layout.jade
Model
     app.js
     package.json
     public
          images
          javascripts
          stylesheets
              style.css
     routes
         index.js
     views
        index.jade
        layout.jade
routes
                app.js
     routes = require('./routes')
     app.get('/', routes.index);


         routes/index.js
exports.index = function(req, res){
   res.render('index', { title: 'Express' })
};
model
  mongoDB
  mongoose = require('mongoose');
  Schema = mongoose.Schema;
  Files = new Schema(
        { 'display_name': String,
          'real_name' : String,
          'tag'         : [String]}
  );
  mongoose.model('Files', Files);
  exports.Files = function(db) {
     return db.model('Files');
  }
Model

var tours = Tours.find();
Model

var tours = Tours.find();


Tours.find({}, function(err, tours){
     res.render('index', {title: 'tours', tours: tours});
   }
);
Model

app.get("/", function(req, res) {
 var Tours = require('./model/tours').Tours(db);

  Tours.find({}, function(err, tours){
    res.render('index', {title: 'tours', tours: tours});
  });
});
View

each tour in tours
 tr
   - var dt = tour.journal[0].date.getFullYear() + (ry
   td #{dt}
   td
     a(href="/show/#{tour._id}") #{tour.title}
   td #{tour.journal[0].theme}
   td
     a(href="/delete/#{tour._id}")
scope

app.js routes   model



node.js

mongooDB   Array
mongoDB
Journal = new Schema(
   { 'date': Date
     'highway':      {type: Number, default:0},
     'others':      {type: Number, default:0}
   }
);
Tours = new Schema(
   { 'title':   String,
     'journal': [Journal]
   }
);
node.js




http://www.craftgear.net/ref/nodesg_west_00/presentation.html
Expressを使ってみた

Expressを使ってみた