Wzorce projektowe dla aplikacji enterprise w Node.js
Authors:
github.com/rootsher
github.com/rkaw92
Authors:
github.com/rootsher
github.com/rkaw92
podejście tradycyjne
|
podejście promisowe
|
mongodb.MongoClient.connect('url', 'testDB', function (err, database) {
if (err) {
throw err;
}
http.createServer(function (req, res) {
database.collection('user').find().toArray(function (err, findResult) {
if (err) {
throw err;
}
res.end(JSON.stringify(findResult));
});
});
});
function database() {
var connectionURL = 'mongodb://localhost:27017';
var databaseName = 'testDB';
this.provides(function () {
var MongoClient = mongodb.MongoClient;
return nodefn.call(MongoClient.connect.bind(MongoClient), connectionURL, databaseName);
});
}
function web() {
this.requires('database');
this.provides(function (dependencyGetter) {
var database = dependencyGetter('database');
http.createServer(function (req, res) {
database.collection('user').find().toArray(function (err, findResult) {
if (err) {
throw err;
}
res.end(JSON.stringify(findResult));
});
});
});
}
manager.runModules([database, web]).done(function applicationCompositionFinished(results) {
console.log('Composition finished! The application is now running.');
}, function handleCompositionError(error) {
console.error('Composition error:', error);
});
when.js - https://www.npmjs.org/when
app-compositor - https://www.npmjs.org/app-compositor
wire.js - https://www.npmjs.org/wire
amqplib - https://www.npmjs.org/amqplib
zmq - https://www.npmjs.org/zmq