respond write function in Server Sent Event api not writing back to client

I am writing a persistent real time application that consumes a Server Sent Event API. I am using NodeJS as listening client and another NodeJS as SSE api that act as a server. The both api worked as expected as the client api consumed and receives persistent message from the SSE Server but there are some logical errors.

***The Problem

a) Inside the Server Sent Event api route “/sample/api/v1/test”, the respond write function message inside the set Interval function was not executed but if there is any syntax error inside the set Interval function, it would be detected but it was not writing message back to the listening client using the response write function when inside the set Interval.

b) The callback function inside the transporter send Mail function, the conditional checking of the callback function(error, response) to know if email is sent or not does not send response write function back to the client but it sent console log message to the console of the SSE server running the api.

I am concerned why response write was not sent inside set interval function and inside the transporter send Mail call back function.

// *** THE SERVER SENT EVENT

const express = require("express");
const app = express();
const cors = require('cors');
const bodyParser = require('body-parser');
const nodemailer = require('nodemailer');
const http = require("http");    //DEVELOPMENT PROCESS
const https = require('https'); 

var corsOptions = {  
  origin: 'http://127.0.0.1:3001',
  methods: ["GET","HEAD","PUT","PATCH","POST","DELETE"],  
};

 let emailSenderOptions = (to, subject, htmlToSend, fromEmail) =>{
  return mailOptions = {
   from: fromEmail,
   to : to,
   subject : subject,
   html : htmlToSend   
};
}


app.post('/sample/api/v1/test', (req, res) => {

res.writeHead(200, {
        'Content-Type': 'text/event-stream',
        Connection: 'keep-alive',
        'Cache-Control': 'no-cache',
    });

//this set timeout is not executed and not delaying for 10secs here
setTimeout(function () {
  console.log("Please wait");
}, 10000);


/* The compiler is not executing the res.write message inside the setInterval. I want everything to be sent to client API every 5 seconds.*/

setInterval(() => {
  res.write("Server: API Found");

  res.write(`nConnected at ${new Date()} n n`);

transporter.sendMail(emailSenderOptions(emailSenderOptions("[email protected]", "SAMPLE SUBJECT", "This is a sample as a letter body", "[email protected]"), function (error, response) {
    if (error) {
          
          //for an email that is not sent, this line is not sent to nodejs client
          res.write(`Email could not be sent`);

         /* for an email that is not sent, this line is successfully logged to the console.log of running nodejs server. It means that this line is executed but why is the res.write() not executed or sent to nodejs api*/

         console.log(chalk.red(`Email could not be sent.`));        
    }

    else{
          
         //for an email that is successfully sent, this line is not sent to nodejs client

         res.write(`Email has been sent.`);


    /* for an email that was successfully sent, this line is successfully logged to the console.log of running nodejs server. It means that this line is executed but why is the res.write() not executed or sent to nodejs api*/

         console.log(chalk.green(`Email has been sent`));
    }
}); 


}, 5000);


// compiler only executes the res.write message and send back to listening client from here

  res.write(`nConnected at ${new Date()} n`);

  res.write(`Only from here is sent back to listening client.  n n`);

transporter.sendMail(emailSenderOptions("[email protected]", "SAMPLE SUBJECT", "This is a sample as a letter body", "[email protected]"), function (error, response) {
    if (error) {
          
            //for an email that is not sent, this line is not sent to nodejs client
          res.write(`Email could not be sent`);

         /* for an email that is not sent, this line is successfully logged to the console.log of running nodejs server. It means that this line is executed but why is the res.write() not executed or sent to nodejs api*/

         console.log(chalk.red(`Email could not be sent.`));        
    }

    else{
          
         //for an email that is successfully sent, this line is not sent to nodejs client

         res.write(`Email has been sent.`);


    /* for an email that was successfully sent, this line is successfully logged to the console.log of running nodejs server. It means that this line is executed but why is the res.write() not executed or sent to nodejs api*/

         console.log(chalk.green(`Email has been sent`));
    }
}); 

});

================================NODEJS CLIENT

const express = require("express");
const app = express();
const http = require('http');
const https = require('https');
const fs = require("fs");
const checkinternetconnected = require('check-internet-connected');
const axios = require('axios');
var EventSource = require('eventsource');


app.use(express.json()); 

var server = http.createServer(app);

var connected = true;

const requestService = () =>{  

  var url = `/sample/api/v1/test`

  let payload = {
    username: username,
  };
  
  axios({
    url: url,
    method: 'post',
    data: payload
  })
  .then(function (response) {
      // your action after success
      console.log(response.data);
  })
  .catch(function (error) {
     // your action on error success
      console.log(error);
  });
}

const persistentRespond = (req, res) => {
  try {
    const e = new EventSource('http://127.0.0.1:3002/xc3113n77001z/api/v1/subscribe');

      e.addEventListener("Server Respond: ", (e) => {
        const data = e.data;

       // Your data
        console.log(`${data}`)
        
    })
    
res.on('close', () => {
        e.removeEventListener("Server Closed", (e) => {
      });
    })
  } catch (err) {
    console.log(err)
  } 
}


server.listen(port, host);
server.on('listening', function() {
    console.log(`Waiting for respond from server application n n `);

requestService();

persistentRespond();

});

***What I expected

  1. I wanted response write function to write message to the listening client every 5 seconds from inside set interval function.

  2. I wanted to write back to the listening client from transporter send mail function call back function if the email was sent or not.