Locals
Connect/Express middleware which appends a locals object for scoped request variables.
Installation
$ npm install connect-locals
Usage
var locals = ;
locals( request, response, next )
Connect/Express middleware which appends a locals object
for scoped request variables.
var app = ;app;app;app;{console;// returns undefined;}{// Append data to the `locals` object...reqlocalsdata = 'beep';;}
Notes
-
If a
request
object already has a definedlocals
property, the middleware does not overwrite the existing value. -
The intent of the
locals
object is similar to Express' res.locals, except the latter is primarily for populating view templates. This module helps avoid possible collisions and separate concerns. -
To ensure that the
locals
object is available to all subsequent middleware, mount the middleware at the top of the middleware stack.var app = ;app;app;app;app;app;
Examples
var express =request =locals = ;{process;{reqlocalsdata = 'beep';;}}{reqlocalsdata = reqlocalsdata;;}{res;;}{;}{if errthrow err;console;console;process;}var app = ;app;app;app;
To run the example code from the top-level application directory,
$ node ./examples/index.js
Tests
Unit
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
License
Copyright
Copyright © 2015. Athan Reines.