spur-common
Version:
Common node library that is implemented through the use of spur-ioc and bluebird promises.
108 lines (77 loc) • 2.32 kB
Markdown
Common node library that is implemented through the use of spur-ioc and bluebird promises.
The project is still a work in progress. We are in the middle of making adjustments and are starting to dogfood the module in our own applications.
[](http://badge.fury.io/js/spur-common)
[](https://travis-ci.org/opentable/spur-common)
```bash
$ npm install spur-common --save
```
To see the latest list of the default dependencies that are injected, check out the [injector.coffee](src/injector.coffee) file.
Libraries: (injection alias/library)
```javascript
{
"_" : "lodash"
"Promise" : "bluebird"
"fs" : "fs"
"path" : "path"
"SpurErrors" : "spur-errors"
"winston" : "winston"
"moment" : "moment"
"superagent" : "superagent"
}
```
Others:
```javascript
{
"console" : console
"nodeProcess" : process
}
```
Directory contents from src/:
```javascript
[
"core"
"fixtures"
"http"
"logging"
"promisify"
"utils"
]
```
Note: Any injectors in which you merge this library to will get all of these dependencies by default.
```javascript
var spur = require("spur-ioc");
var spurCommon = require("spur-common");
module.exports = function(){
// define a new injector
var ioc = spur.create("demo");
// register node modules to be injected
ioc.registerLibraries({
...
});
// register already constructed objects such as globals
ioc.registerDependencies({
...
});
// register folders in your project to be autoinjected
ioc.registerFolders(__dirname, [
"demo"
]);
// THIS IS THE IMPORTANT PART: Merge the spur-common dependencies to your local container
ioc.merge(spurCommon)
return ioc;
}
```
```javascript
injector = require "./src/injector"
injector().inject (UncaughtHander, Logger)->
Logger.info "Starting app..."
// Here you would inject your dependencies like WebServer or runtime class and start it.
// Enabled the UncaughtHander
UncaughtHander.listen()
```