expressa-init-collection
v1.0.0
Published
description here
Downloads
2
Readme
file-based design-pattern to organize expressa & express REST/db middleware
Usage
require('expressa-folder')(expressa, app)
expressa.addListener('ready', 100, >(){
expressa.folderDir = __dirname+"/lib"
expressa.initFolder('foo') // will require expressa db/REST-listener code if collection 'foo' exist
expressa.initFolder('foo/bar') // will setup custom express point
})
This will automatically fetch the following files if present:
| file | expressa listener | creates express endpoint | note | | - | - | - | - | | lib/foo/get.js | yes | no | requires data/collection/foo.js to exist | | lib/foo/put.js | yes | no | requires data/collection/foo.js to exist | | lib/foo/delete.js | yes | no | requires data/collection/foo.js to exist | | lib/foo/schema.js | yes | no | requires data/collection/foo.js to exist | | lib/foo/functions.js | no | no | all db objects will inherit these functions | | lib/foo/bar/get.js | no | yes | |
Example: lib/foo/get.js
module.exports = function(expressa, app){
return function(req, collection, doc, resolve, reject) {
// do stuff with the response data (doc)
resolve(doc)
})
}
Example: lib/foo/functions.js
module.exports = function(expressa, app){
return {
addPropertyFoo: () => {
this.foo = "bar"
}
}
}
Now you can easily access helper functions on the server:
expressa.db.foo.find({})
.then( function(items){
items.map( (i) => i.addPropertyFoo() )
})
Example: lib/foo/bar/get.js
module.exports = function(expressa,app){
return function(req, res, next){
res.end("foo")
}
}
Voila..this will automatically setup a 'foo/bar' express-endpoint