Skip to content
Myr

index.js

This file

Path

examples/ejs/index.js

50 lines · 1.1 KiB · JavaScript

Last changed by

Merge branch 'examples'TJ Holowaychukbefore adoptionc492cde

History of this file

Take it

The walk stopped after 200 commits: lines older than 214f913 point at it.

mergeTJ Holowaychukbefore adoption214f913

lines 1–33why, one step back
1
2/**3 * Module dependencies.4 */56var express = require('../../');78var app = module.exports = express();910// Register ejs as .html. If we did11// not call this, we would need to12// name our views foo.ejs instead13// of foo.html. The __express method14// is simply a function that engines15// use to hook into the Express view16// system by default, so if we want17// to change "foo.ejs" to "foo.html"18// we simply pass _any_ function, in this19// case `ejs.__express`.2021app.engine('.html', require('ejs').__express);2223// Optional since express defaults to CWD/views2425app.set('views', __dirname + '/views');2627// Without this you would need to28// supply the extension to res.render()29// ex: res.render('users.html').30app.set('view engine', 'html');3132// Dummy users33var users = [

Merge branch 'examples'TJ Holowaychukbefore adoptionc492cde

lines 34–36why, one step back
34 { name: 'tobi', email: 'tobi@learnboost.com' },
35 { name: 'loki', email: 'loki@learnboost.com' },36 { name: 'jane', email: 'jane@learnboost.com' }

mergeTJ Holowaychukbefore adoption214f913

lines 37–39why, one step back
37];
3839app.get('/', function(req, res){

Merge branch 'examples'TJ Holowaychukbefore adoptionc492cde

lines 40–44why, one step back
40 res.render('users', {
41 users: users,42 title: "EJS example",43 header: "Some users"44 });

mergeTJ Holowaychukbefore adoption214f913

lines 45–50why, one step back
45});
4647if (!module.parent) {48 app.listen(3000);49 console.log('Express app started on port 3000');50}