0.0.1 • Published 12 years ago

tempdata v0.0.1

Weekly downloads
7
License
-
Repository
github
Last release
12 years ago

TempDataJS

Simple ASP.NET MVC-like TempData provider for Node.js applications. Values added to tempData live until they are retrived or the end of a session, whichever comes first.

Example

Using tempData could not be easier. Once all setup is done, start adding values using req.tempData.set(name, value) and retrieving them using req.tempData.get(name).

	var tempData = require('tempData');
	var app = express();

	app.configure(function() {
		...

		// This has to appear BEFORE the router
		app.use(express.cookieParser());
		app.use(express.session({ secret: 'your_super_secret_session_key' })); // please change this!
		app.use(tempData);
		
		...
	});

	...

	// Routes
	app.get('/', function(req, res) {
		// Retrieve tempData value here. It won't exist unless the request
	  	// was redirected
		var tempVal = JSON.stringify(req.tempData.get('test_val'));

		res.render('index', { title: 'Express', temp: tempVal });
	});

	app.post('/', function(req, res) {
	  // Set tempData value here
		req.tempData.set('test_val', { x: 'Hello World!' });
		
		res.redirect('/');
	});

	...

Installation

Pending npm submission. Stay tuned.

Usage