title: Session of Node API working in postman well but not in browser
body: <p>I am creating a node API for authentication, in my node API I have created a login session and storing it. Now the problem is that it's working in postman well, but in the browser, it's not working. I am assuming its a problem with cookies setting, being new in node please give me a proper suggestion for this issue. I have given the codes.</p>
  
  <p>In app.js set the express-session in this way. </p>
  
  <pre><code>app.use(session({ secret: 'middesecrectcode', resave:false, saveUninitialized:true }))
  </code></pre>
  
  <p>In my API routes, I have done that.</p>
  
  <pre><code> router.post('/testlogin', function(req, res, next){  
      req.session.username = "midde";
      res.send("Your session has been created as "+ req.session.username); 
      req.session.success = true;
  });
  
  
  router.get('/checkSession', function(req, res, next){
     console.log(req.session.success); 
     if(req.session.username){
      res.send("hello "+req.session.username);  
     } 
     else{
         res.send("session is not SET");
     }
  });
  
  router.get('/logout', function(req, res, next){
      req.session.destroy(function(err){
         if(err){
             console.log("Some error received when to logout");
         }
         res.send("You have got logged out successfully");
      });
  });
  </code></pre>
  
  <p>And in the browser i am calling the API in the following way</p>
  
  <p><strong>login.html</strong></p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"&gt;&lt;/script&gt;
          &lt;script type='text/javascript' src="login.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
        &lt;div&gt;
          &lt;label&gt;&lt;b&gt;Username&lt;/b&gt;&lt;/label&gt;
          &lt;input type="text" placeholder="Enter Username" name="uname" id="uname"&gt;
          &lt;/br&gt;
          &lt;label&gt;&lt;b&gt;Password&lt;/b&gt;&lt;/label&gt;
          &lt;input type="password" placeholder="Enter Password" name="psw" id="pwd"&gt;
          &lt;/br&gt;
  
          &lt;button id="btn" type="submit"&gt;Login&lt;/button&gt;
        &lt;/div&gt;
  
        &lt;div&gt;
            &lt;button id="btnSession" type="submit"&gt;Check Session&lt;/button&gt;
        &lt;/div&gt;
      &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>login.js</strong></p>
  
  <pre><code>$(document).ready(function(){
      $("#btn").click(function(){
          var uname = $("#uname").val();
          var pwd = $("#pwd").val();
  
          var dataSet = {
              "username" : uname,
              "password": pwd
              } 
          var data2send = JSON.stringify(dataSet) 
           console.log(data2send);
  
         $.ajax({
                  url: "http://localhost:8080/api/testLogin",
                  type: "post",
                  data: data2send,
                  contentType: 'application/json',
                  success: function(d) {
                      alert(d);
                  }
              });
  
      });
  
      $("#btnSession").click(function(){   
         $.ajax({
                  url: "http://localhost:8080/api/checkSession",
                  type: "get",
                  contentType: 'application/json',
                  success: function(d) {
                      alert(d);
                  }
              });
  
      });
  
  });
  </code></pre>