index.js
This file
Path
examples/ejs/index.js
57 lines · 1.3 KiB · JavaScript
Last changed by
docs: replace dummy with placeholder in example comments (#7064)Sam Tucker-Davisbefore adoption6c4249f
History of this fileTake it
The walk stopped after 200 commits: lines older than 2027b87 point at it.
fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87
lines 1–7why, one step back1'use strict'23/**4 * Module dependencies.5 */67var express = require('../../');fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 8why, one step back8var path = require('node:path');fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87
lines 9–37why, one step back910var app = module.exports = express();1112// Register ejs as .html. If we did13// not call this, we would need to14// name our views foo.ejs instead15// of foo.html. The __express method16// is simply a function that engines17// use to hook into the Express view18// system by default, so if we want19// to change "foo.ejs" to "foo.html"20// we simply pass _any_ function, in this21// case `ejs.__express`.2223app.engine('.html', require('ejs').__express);2425// Optional since express defaults to CWD/views2627app.set('views', path.join(__dirname, 'views'));2829// Path to our public directory3031app.use(express.static(path.join(__dirname, 'public')));3233// Without this you would need to34// supply the extension to res.render()35// ex: res.render('users.html').36app.set('view engine', 'html');37docs: replace dummy with placeholder in example comments (#7064)Sam Tucker-Davisbefore adoption6c4249f
line 38why, one step back38// Placeholder usersfix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87
lines 39–57why, one step back39var users = [40 { name: 'tobi', email: 'tobi@learnboost.com' },41 { name: 'loki', email: 'loki@learnboost.com' },42 { name: 'jane', email: 'jane@learnboost.com' }43];4445app.get('/', function(req, res){46 res.render('users', {47 users: users,48 title: "EJS example",49 header: "Some users"50 });51});5253/* istanbul ignore next */54if (!module.parent) {55 app.listen(3000);56 console.log('Express started on port 3000');57}