Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jsantell/node-request-extend
Jumps in your middleware and extends route requests with references
https://github.com/jsantell/node-request-extend
Last synced: about 2 months ago
JSON representation
Jumps in your middleware and extends route requests with references
- Host: GitHub
- URL: https://github.com/jsantell/node-request-extend
- Owner: jsantell
- License: mit
- Created: 2012-07-06T03:45:08.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-07-21T19:26:47.000Z (over 12 years ago)
- Last Synced: 2024-11-17T11:06:46.830Z (2 months ago)
- Language: JavaScript
- Homepage: https://npmjs.org/package/request-extend
- Size: 110 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
node-request-extend
================Jumps in your middleware and extends route requests with references
## Installation ##
`npm install request-extend`
## Methods ##
`reqExtend([namespace,] object [, force]);`
Merges `object`'s keys and values with a routes request variable, which optionally can be contained under a property of `namespace`. `force` defaults to true, and controls whether or not `object` values should overwrite properties already on the request variable.## Usage ##
```javascript```
var
express = require( 'express' ),
reqExtend = require( 'request-extend' ),
app = express.createServer();var
models = {
user : require( './models/user' ),
data : require( './models/data' )
},
config = require( './config' );app.configure(function () {
app.set( 'views', __dirname + '/views' );
app.set( 'view engine', 'jade' );
app.use( reqExtend( 'models', models ));
app.use( reqExtend( 'config', config ));
app.use( express.static( __dirname + '/public' ));
app.use( app.router );
});
```Adds `req.models.user`, `req.models.data` and `req.config` to all requests in your routes.
```javascript
app.get( '/users', function ( req, res, next ) {
res.render( 'users', { users: req.models.user });
});
```## Tests ##
Run `node tests/runTests.js` from project root -- testing uses `nodeunit`