express-locals

Mixin properties into the `res.locals` object for each request

Usage no npm install needed!

<script type="module">
  import expressLocals from 'https://cdn.skypack.dev/express-locals';
</script>

README

Express Locals

Mixin properties into the res.locals object for each request

Usage

app.get('/my-route'
, require('express-locals')({
    hello: 'world'
  , objects: [{ a: 1 }, { a: 2 }, a: 3 }]
  })
, function( req, res ){
    res.send( res.locals.hello );
  }
);

Install

npm i -S express-locals

Test

npm test

Options

{
  // Deep clones the passed in object at each request
  cloneDeep: true // (default)
}

usage:

app.get('/my-route'
, require('expresss-locals')({ a: 1 }, { cloneDeep: false })
, myHandler
);