view engine setup express

// Step 1: Import required modules
const express = require('express');
const path = require('path');

// Step 2: Create an Express application
const app = express();

// Step 3: Set the view engine to 'ejs' (or another view engine of your choice)
app.set('view engine', 'ejs');

// Step 4: Set the views directory to the 'views' folder (or another folder of your choice)
app.set('views', path.join(__dirname, 'views'));

// Step 5: Define a route to render a view
app.get('/', (req, res) => {
  // Step 6: Render the 'index.ejs' view
  res.render('index', { title: 'Express View Engine Example' });
});

// Step 7: Start the server and listen on a specified port (e.g., 3000)
app.listen(3000, () => {
  console.log('Server is running on port 3000');
});