title: How to handle query string Node Js AWS Lambda
body: <p>I am using AWS Lambda to create a fetch API by passing a query parameter eg. vendorId, but in some case, I need whole data without passing the query parameter and in that case, my code is broken.
  Let me know how I can handle the query parameter.</p>
  
  <pre><code>  var mysql=require('mysql'); //Require whatever connector you need.
  
    function getConnection()
     {
          var params={
             host     : 'myhostinfo',
             user     : 'myuser',
              password : 'mypwd',
             database : 'mydb'
      };
  
  return mysql.createConnection(params);
  }
        //This is your handler.
       exports.handler=function(event, context,callback)
      {
  
   //This is declared inside the handler: it is guaranteed to never be reused!.
     var connection=getConnection();
  var fetchvendors="";
  
  
  if(event.query.vendorid)
  {   
      var vendorid=parseInt(event.query.vendorid);
      fetchvendors="SELECT v.*,c.vcategoryname FROM `tbl_vendors` v LEFT 
   OUTER JOIN tbl_demo_categories c ON v.vendorcatid=c.vcategoryid WHERE 
    v.vendorid="+vendorid;
  }
  
  else{
         fetchvendors="SELECT v.*,c.vcategoryname FROM `tbl_vendors` v LEFT 
  OUTER JOIN tbl_demo_categories c ON v.vendorcatid=c.vcategoryid WHERE 
   status=1";
  }
       connection.query(fetchvendors, function (error, results, fields) {
            if (error) {
              connection.destroy();
               throw error;
            } else {
                // connected!
               callback(null, results);
               connection.end();
          }
       });
    }
  </code></pre>
  
  <p>here is the result</p>
  
  <pre><code>          Response:
          {
                "errorMessage": "RequestId: 42fd18b1-598c-4f7e-b93b- 
                  b146777772b2 
              Process exited before completing request"
                 }
  
            Request ID:
                "42fd18b1-598c-4f7e-b93b-b146777772b2"
  
               Function Logs:
              START RequestId: 42fd18b1-598c-4f7e-b93b-b146777772b2 Version: 
          $LATEST
               2019-04-04T10:48:34.959Z   42fd18b1-598c-4f7e-b93b- 
            b146777772b2  TypeError: Cannot read property 'vendorid' of 
                         undefined
  </code></pre>