services-stack
v1.2.0
Published
models stack utility
Downloads
4
Readme
services-stack
Stack recursively services file on array.
You can stack function
, object
or class
.
installation
npm install services-stack
Usage
if services file is a function
, context will be automatically inject.
if services file is a class
or object
, you need to pass manualy the context, via new
for example
context
is an object
. It contains a service()
function. this allow to get services from another service.
models/
contacts.js // object
other.js // function
user/user.js // class
...
const context = {
db : db,
config : config,
...
};
const services = require('services-stack')({
path : './models'
context: context
});
const contact = services.get('contacts');
Example of a service.
module.exports = ctx => {
const db = ctx.db;
const contacts = ctx.service('contacts');
return {
...
}
}