how to make pages from list in nodejs

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

// Step 2: Define the list of pages
const pageList = ['home', 'about', 'contact'];

// Step 3: Create a function to generate HTML content for each page
function generatePageContent(page) {
  return `<html>
<head>
  <title>${page}</title>
</head>
<body>
  <h1>${page} Page</h1>
  <p>This is the ${page} page content.</p>
</body>
</html>`;
}

// Step 4: Create a directory to store the pages
const pagesDirectory = path.join(__dirname, 'pages');

if (!fs.existsSync(pagesDirectory)) {
  fs.mkdirSync(pagesDirectory);
}

// Step 5: Generate and save HTML content for each page
pageList.forEach((page) => {
  const pageContent = generatePageContent(page);
  const filePath = path.join(pagesDirectory, `${page}.html`);
  fs.writeFileSync(filePath, pageContent);
  console.log(`${page}.html created.`);
});

// Step 6: Display a success message
console.log('Pages generation completed.');

Make sure to run this script using Node.js. This script will create an output directory named "pages" and generate HTML files for each page specified in the pageList array.