How would MVC-like code work in Node.js?
http://boldr.net/mvc-stack-node-js-ejsgi-scylla-mustache is a great little article with a full github example of a MVC pattern using dirfferent Node modules. It also lists alternate modules currently available. It answered this question for me better than http://howtonode.org/ which has some good tuts but I couldn't find anything on MVC there.
The easiest way to do this is with expressjs, which is an MVC framework for Node. Node is just what it says, evented I/O for the web.
The example on the http://expressjs.com should help with the basics but to answer your question directly.
var express = require('express');var app = express.createServer();app.get('/whatever', function(req, res) { Things1.objects.getAll(function(things1) { Things2.objects.getAll(function(things2) { var options = { locals: { things1: things1, things2: things2 }}; res.render('thingstemplate.ejs', options); // or thingstemplate.jade or whatever }); });});app.listen('80', ''); // port and optional hostname to bind
TowerJS is a popular MVC framework based on
- MongoDB (database)
- Redis (background jobs)
- CoffeeScript
- Stylus
- Jasmine (tests)
- jQuery
Site http://towerjs.org/