title: Can you render a template in express and then change it when a condition is met?
body: <pre><code>app.post('/', (req, res) =&gt; {
     let x = false
     // function that changes x to true after completing
  
     res.send('function running')
     if(x) {
       res.send('Function complete')
     }
  
  })
  </code></pre>
  <p>I am trying to render a response in express while a function is running. Once it completes, it changes the value of a variable. I want to render a different response once the value of that variable changes. When I tried the above code, I got an error.</p>
  <pre><code>Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
  </code></pre>