Skip to content

Instantly share code, notes, and snippets.

@zeuxisoo
Created February 2, 2012 15:13
Show Gist options
  • Save zeuxisoo/1723915 to your computer and use it in GitHub Desktop.
Save zeuxisoo/1723915 to your computer and use it in GitHub Desktop.
simple test on ExpressJS share the config.js variable

app.js

var config = require(__dirname + '/kernel/config.js');

app.config = config;

app.get('/', controllers.index(app).index);

controllers/index.js

exports.index = function(app) {
	return {
		index: function(req, res) {
			res.render('index', { title: app.config.site_name })
		}
	};
}

app.js

var config = require(__dirname + '/kernel/config.js');

app.config = config;

controllers.index(app);

controllers/index.js

exports.index = function(app) {
	app.get('/', function(req, res) {
		res.render('index', { title: app.config.site_name })
	});
}

Structure

  • controllers/index.js
  • kernel/config.js
  • app.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment