Skip to content

Instantly share code, notes, and snippets.

@d-adamkiewicz
Created January 23, 2014 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d-adamkiewicz/8582276 to your computer and use it in GitHub Desktop.
Save d-adamkiewicz/8582276 to your computer and use it in GitHub Desktop.
express and express-yui example
var express = require('express'),
exphbs = require('express3-handlebars'),
expyui = require('express-yui'),
app = express();
expyui.extend(app);
// register file extension
app.engine('hbs', exphbs());
app.set('view engine', 'hbs');
app.get('/', expyui.expose(), function(req, res, next) {
res.expose({
resMsg: "Message passed on '/' request"
});
res.render('index');
});
app.listen(3000);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test App</title>
</head>
<body>
<h1>Test App</h1>
<div id="content"></div>
<script>
{{{state}}}
</script>
<script>
app.yui.use('node', function(Y) {
/***
* resMsg is 'global' variable serialized/passed in {{{state}}}
* accessible on '/' request
***/
Y.one('#content').setContent('<p>' + resMsg + '</p>');
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment