MERN

⌘K
  1. Home
  2. Docs
  3. MERN
  4. Passing Data to EJS Templates:

Passing Data to EJS Templates:

// app.js
app.get('/', (req, res) => {
  const data = {
    title: 'Express and EJS Tutorial',
    message: 'Welcome to the Express and EJS tutorial!',
  };
  res.render('index', data);
});
<!-- views/index.ejs -->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><%= title %></title>
</head>
<body>
  <h1><%= title %></h1>
  <p><%= message %></p>
</body>
</html>

How can we help?