-
-
Save vengrov/58db0aa55d4d08b56f311217ed29e62e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-web | |
- node-modules | |
- ejs | |
- ejs.js | |
- utils.js | |
- views | |
- main.html | |
- hello.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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