title: How execute code in a certain sequence in nodeJS?
body: <p>I have this issue in nodeJS where the code below the call to 4 async functions is executed before the functions return any data. The code below should return the status of each call in json. How can I execute each function in sequence? So when I return the data to caller its with the updated status or error that happened in each function?</p>
  
  <p>This is what i have now..</p>
  
  <pre><code>let idItem = "";
      let statusInsert = "N/A";
      let statusSms = "N/A";
      let statusEmail = "N/A";
      let msgErro = "N/A";
  
  
      try {
  
          let retorno = inserirEmergencia(req).then(
          iar =&gt; {
              console.log(iar);
              idItem = iar.data.ID;
              statusInsert = "OK";
          }
          );  
  
        } catch (e) {
          //Error handling
          idItem = "0";
          statusInsert = "Erro";
          msgErro += " &gt; " + e.message;
        }
  
        let jsonResposta = 
        {
            "idItem" : idItem,
            "statusInsert" : statusInsert,
            "statusSms" : statusSms,
            "statusEmail" : statusEmail,
            "msgErro" : msgErro
        }
  
        res.json(jsonResposta);
  </code></pre>
  
  <p>so, jsonResposta has the initial values, how can i execute four functions like that and be sure that at the end the value is the actual function returns?</p>