express-dataz-context

1.0.0 • Public • Published

Express Dataz Context

Adds an instance of Dataz onto res.locals in an express app. This is for exposing data to the front-end of a web app.

Install

$ npm install --save express-dataz-context

Basic Usage

var express = require('express'),
	context = require('express-dataz-context');

var app = express();
app.use(context);

app.get('/', function(req, res) {
	// Get and add some data to the context
	res.locals.context.set('someData', {
		title: 'Data that needs escaping<script>alert('injection');</script>'
	});
	res.render('index.html');
});

/* Index Template:

<html>
	<head>
		<title><%= context.get('someData:title') %></title>
		<script>
			var pageData = <%- context.escape(true) %>;
			// {"someData":{"title":"Data that needs escaping&lt;script&gt;alert('injection');&lt;/script&gt;"}}
		</script>
	</head>
	<body></body>
</html>
*/

Readme

Keywords

Package Sidebar

Install

npm i express-dataz-context

Weekly Downloads

1

Version

1.0.0

License

ISC

Last publish

Collaborators

  • wesleytodd