Using templatesUsing locals and conditional templates

Partials

default.ejs
<!DOCTYPE html>
<html>
<head><% include partials/head.ejs %></head>
<body>
<h1><%= title %></h1>
<p><%= content %></p>
</body>
</html>
/partials/head.ejs
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title><%= title %></title>
index.js
var express = require('express');
var app = express();

app.set('view engine', 'ejs');

app.get('/', function(req, res) {
  console.log('/ requested');
  res.render('default', { title: 'Hello', content: 'Heyyy salut-donc !' });
})

// si on a autre chose
app.get('*', function(req, res) {
  console.log('Page inconnue demandée');
  res.render('default', { title: '😭', content: '😭😭😭'});
})

var server = app.listen(3000, function() {
  console.log('Listening on port 3000.');
})