bem/bem-tools — pull request #280 by serzhit (2012-10-15 11:22:52+00:00)
Title: Adding node.js tech for using bem with backend on node/express

This technology makes possible to make node.js/express backend using BEM. You create blocks with technology 'node.js'.
Every block creating oblect exports[blockname] = Object. Object is inherited from class definition which you make in separate file.
You could use db, req & res variables in these declarations which correspond to db instance and request/response objects.
After bem build you could 'require' your file from the express 'route' files like this:

/*
* Module requirements
*/

var inherit = require('inherit')
, Server = require('mongodb').Server
, Db = require('mongodb').Db
, Connection = require('mongodb').Connection;

exports.db = db = new Db('ruskline', new Server("127.0.0.1", 27017, {}), {});

/*
* GET home page.
*/

exports.index = function(req, res){

exports.req = req;
exports.res = res;
var context = require('../pages/lenta/lenta.node.js');

res.render('lenta/lenta', context, function(err, str) {
if(err) throw err;
res.send(str);
});
};