index.js
This file
Path
examples/ejs/index.js
50 lines · 1.2 KiB · JavaScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 6bc7574 point at it.
docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 1–50why, one step back1/**2 * Module dependencies.3 */45var express = require('../../');67var app = module.exports = express();89// Register ejs as .html. If we did10// not call this, we would need to11// name our views foo.ejs instead12// of foo.html. The __express method13// is simply a function that engines14// use to hook into the Express view15// system by default, so if we want16// to change "foo.ejs" to "foo.html"17// we simply pass _any_ function, in this18// case `ejs.__express`.1920app.engine('.html', require('ejs').__express);2122// Optional since express defaults to CWD/views2324app.set('views', __dirname + '/views');2526// Without this you would need to27// supply the extension to res.render()28// ex: res.render('users.html').29app.set('view engine', 'html');3031// Dummy users32var users = [33 { name: 'tobi', email: 'tobi@learnboost.com' },34 { name: 'loki', email: 'loki@learnboost.com' },35 { name: 'jane', email: 'jane@learnboost.com' }36];3738app.get('/', function(req, res){39 res.render('users', {40 users: users,41 title: "EJS example",42 header: "Some users"43 });44});4546/* istanbul ignore next */47if (!module.parent) {48 app.listen(3000);49 console.log('Express started on port 3000');50}