Node module to allow CQRS-ing with Meteor
npm install meteor-wapi



Node module to allow CQRS-ing with Meteor.
npm i --save meteor-wapi
``js
var express = require("express");
var MongoClient = require("mongodb").MongoClient;
var MW = require("meteor-wapi");
var mongoUrl = process.env.MONGO_URL || "mongodb://localhost:3001/meteor";
MongoClient.connect(mongoUrl, function (err, db) {
var mw = new MW(db);
var optionalContext = {
prefix: "echo: "
};
mw.methods({
echo: function (string) {
return this.prefix + string;
}
}, optionalContext);
var app = express()
.use("/call", mw.getRouter())
.listen(process.env.PORT || 4000);
});
`
Creates a new MW instance.
##### Arguments
* db MongoClient connection _required_: a mongodb connection, as returnedMongoClient.connect
(via callback) by the method.
##### Returns
An MW instance.
Registers one or more remote methods (mimicking Meteor's API). The methods will
be invoked when the client POSTs a DDP method message to the server.
Methods can either:
* throw an error
* return a value
* return a promise
If the method returns a value (or an eventually fulfilled promise), the client
will receive the returned (or resolved) value in the DDP response message.
If the method throws (or returns an eventually rejected promise), the client
will receive the error in the DDP response message. If the error is an instance
of MW.Error, its code and message will be used for the reply. Otherwise a500 INTERNAL SERVER ERROR
generic error will be used.
##### Arguments
* methodsMap string-function dictionary _required_: a dictionary of
functions (just like in Meteor).
* optionalContext object _optional_: an optional object which will bethis
mixed in with the execution context of the method (the value).
##### Returns
Nothing.
Returns an express router which listens for POSTed DDP method messages,
authenticates them and runs the appropriate methods.
##### Arguments
None.
##### Returns
An express router (to be used as argument to an express app use method).
After cloning the repository and installing dependecies with npm install:
* to run unit tests: npm run unit-testsnpm run integration-tests` (you need a running
* to run integration tests:
local mongo listening on port 27017)