express get cookie

// Step 1: Require the 'express' module
const express = require('express');

// Step 2: Create an instance of the express application
const app = express();

// Step 3: Define a route that handles a GET request
app.get('/getCookie', (req, res) => {
  // Step 4: Use the 'req.cookies' object to access cookies
  const myCookie = req.cookies.myCookie;

  // Step 5: Check if the cookie exists
  if (myCookie) {
    // Step 6: If the cookie exists, send its value in the response
    res.send(`Value of myCookie: ${myCookie}`);
  } else {
    // Step 7: If the cookie doesn't exist, send a message indicating so
    res.send('Cookie not found');
  }
});

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