Igloo
Igloo is a library of components built with electrolyte to be used as building blocks for an app.
Need to view documentation for a given component? See Components below.
Index
Sponsor
Install
Please use eskimo which has igloo built-in.
However you can use igloo in your own project by installing it.
npm install -s igloo
Usage
You will need to first require('igloo')
, define a "config" component, and then use electrolyte
's IoC.loader
method to load igloo
's components ([listed below][#components]).
Note that
igloo
requires you to have defined a "config" component (sinceigloo
's "setting" component requires it as a dependency). For example, Eskimo defines a "config" component here.
// boot/config.js exports = module { return defaults: logger: console: true requests: true mongo: false file: false hipchat: false output: handleExceptions: true colorize: true prettyPrint: false development: server: port: 3000 production: server: port: 3080 logger: requests: false output: colorize: false prettyPrint: false } exports'@singleton' = true
You can have a boot/local.js
with local settings if you need something unversioned (and load it when the environment is development
— default).
// boot/local.js var path = var uploadsDir = pathvar maxAge = 30 * 24 * 60 * 60 * 1000 exports = module { return uploadsDir: uploadsDir server: host: '0.0.0.0' env: 'local' port: 3003 mongo: dbname: 'igloo-local' redis: prefix: 'igloo-local' maxAge: maxAge } exports'@singleton' = true
// app.js var IoC = var igloo = var path = var express = var winstonRequestLogger = IoCIoC // logger componentvar logger = IoClogger // settings componentvar settings = IoC // basic server var app = // winston request logger before everything else// but only if it was enabled in settingsif settingsloggerrequests app app app
Components
Returns a function which accepts templateName, locals, headers, transport, and callback arguments. This component uses
// example - email // TODO: finish this! // mention that transport defaults to settings.email.transport // mention that headers inherits settings.email.headers // but only if you don't set `headers.useDefaults: false` // note that is also uses `settings.email.templates` object// which can have `dir` string and `options` object for node email-templates pkg // also document about having `transport` of `settings.email.transport` be an// actual transporter already pre-created (possibly with plugins like html-to-text)
error-handler
Returns Express route middleware for error handling.
// example - error handler var _ = var errorHandler = IoC app // you could also do:// app.post('/user', createUser)// app.use(errorHandler)// but make sure that `app.use(errorHandler)`// is the very last route middleware to be `use`'d { if !_ return // ... create a user in your db res }
knex
Returns a Knex SQL database connection using
settings.knex
.
// example - knex var knex = IoC app
logger
Returns a Winston logger object with pre-configured transports using
settings.logger
andsettings.output
.
// example - logger var logger = IoC logger
mongo
Returns a MongoDB NoSQL connection using
settings.logger
,settings.output
, andsettings.mongo
and Mongoose ORM.
TODO: Should we rename this to
igloo/mongoose
?
// example - mongo var validator = var mongoose = IoC var User = email: type: String required: true unique: true validate: validatorisEmail mongoose
mongoose-plugin
Returns a Mongoose plugin helper for common schema additions.
// example - mongoose plugin var validator = var mongoose = IoCvar mongoosePlugin = IoC var User = email: type: String required: true unique: true validate: validatorisEmail User mongoose
server
Returns a function which accepts a callback argument (currently no
err
argument is returned when this callback function is executed). This component starts either a cluster (with one thread per CPU) or a simple single-threaded instance usingapp.listen
. This should be used withapp.phase
using bootable, since bootable's "phases" (app.phase
) method accepts this callback function as a standard argument when defining a "phase" (read more about bootable to understand this please). This component usessettings.logger
,settings.output
, andsettings.server
.
// example - server var bootable = var express = var app = var server = IoCvar logger = IoC // this should always be the last phaseapp app
sessions
Returns a Redis connection using
settings.logger
,settings.output
, andsettings.redis
with express-session and connect-redis.
// example - sessions var session = var express = var app = var sessions = IoCvar settings = IoC // add req.session cookie supportsettingssessionstore = sessionsapp
settings
Returns a settings object using a "config" component defined and loaded by electrolyte in a location such as "boot/config" (see initial example at the top of this Readme).
For a full config example file, see Eskimo's default config.
update-notifier
Returns nothing, as it is used for notifying an app of module updates using update-notifier.
TODO: Look into why this isn't working per https://github.com/yeoman/update-notifier/issues/25
Tests
npm install -dnpm test
Conventions
See nifty-conventions for code guidelines, general project requirements, and git workflow.
Contributors
- Nick Baugh niftylettuce@gmail.com
- Adnan Ibrišimbegović adibih@gmail.com
- Bruno Bernardino me@brunobernardino.com
Credits
- Igloo by VALÈRE DAYAN from The Noun Project
- ESKIMO IGLOO (color palette)