Skip to content

Instantly share code, notes, and snippets.

@vengrov
Last active April 3, 2017 10:38
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 vengrov/58db0aa55d4d08b56f311217ed29e62e to your computer and use it in GitHub Desktop.
Save vengrov/58db0aa55d4d08b56f311217ed29e62e to your computer and use it in GitHub Desktop.
-web
- node-modules
- ejs
- ejs.js
- utils.js
- views
- main.html
- hello.js
// web/scripts/hello.js
var ejs = require('ejs');
var path = require('path');
function getViewPath(viewName) {
return path.resolve(__dirname, 'views/' + viewName + '.html');
}
exports.run = function(request, response) {
var data = { userName: 'john' };
ejs.renderFile(getViewPath('main'), data, function(err, result) {
if (err) {
return response.status(500).send(err.message);
}
response.status(200).send(result);
});
};
<!-- web/views/main.html -->
<html>
<body>
<h2>Hello <%= userName %></h2>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment