title: Create API in node js to get data with multiple queries with my sql
body: <p>I am new to node js. I am trying to develop API for getting items list by its category list. For that i have create a function to fetch all available active featured tags from table ( featured_tags ). After that featured tag list fetch i want to get items list from ( items ) table which belongs to that particular tag. Can anyone help me how to so that in node js. I am using mysql database.</p>
  
  <p>i have done below things to fetch categories from table. </p>
  
  <p>route.js file</p>
  
  <pre><code>this.app.get('/list_menu',async(request,response) =&gt;{
          var itemlist = ''; 
          const featuretags = helper.getFeatureTag().then(function(featuredtags){
                  //console.log('test');
                  itemlist = helper.getitems(featuredtags);
  
              });
          response.status(200).json({
                          status:200,
                          message: "success",
                          data:itemlist
                  });
  
      });
  </code></pre>
  
  <p>function to get active featured tags in helper.js file</p>
  
  <pre><code>async getFeatureTag(){
      return this.db.query("select * from featured_tags where status = 1 order by id desc ");
      //const featuredtags = await this.db.query("select * from featured_tags where status = 1 order by id desc ");
  }
  </code></pre>
  
  <p>Function which get items list of featured tags in helper.js file</p>
  
  <pre><code>async getitems(featuredtags){
      var itemdata = [];
      var featured_tagdataset = [];
      if(featuredtags.length &gt; 0){
          for (var i = 0; i &lt; featuredtags.length; i++) {
              var row = featuredtags[i];
              var featurtag = {};
              featurtag.id = row.id;
              featurtag.featured_tag = row.featured_tag;
              var itemresult = await this.db.query("SELECT * FROM `items` WHERE status = 1 and FIND_IN_SET('"+ row.id +"' ,featured_tags) &gt; 0");
              if(itemresult.length &gt; 0){
                  for(var l=0; l &lt; itemresult.length; l++){
                      var itemrow = itemresult[l];
                      var item = {};
                      item.id = itemrow.id;
                      item.category_id = row.id;
                      item.name = itemrow.item_name;
                      itemdata.push(JSON.stringify(item));
                  }                   
              }
              featurtag.tag_items = itemdata;
              featured_tagdataset.push(featurtag);
          }
          //console.log(featured_tagdataset);
          return featured_tagdataset;         
      }else{
          return null;
      }
  }
  </code></pre>
  
  <p>when i console featuredtag_dataset array in itemlist() in helper.js file it show me perfect response which i have to pass in API response. But  in route.js it shows me blank in data parameter.</p>
  
  <p>Can anyone help me for how to develop this type of APIs in node js.</p>