title: How to get the session value in ejs
body: <p>I am making a login module using session(using express and nodes).
  When the user has logged in, I save the user in the session.</p>
  
  <pre><code>req.session.user= ...
  </code></pre>
  
  <p>How can I get the session value in a .ejs view like:</p>
  
  <pre><code>&lt;label&gt;
              您好！&lt;%= req.session.user.username %&gt;
   &lt;/label&gt;
  </code></pre>
  
  <p>But this doesn't work.</p>
  
  <p>I can do it by this:</p>
  
  <pre><code>router.get('/home',function(req, res){
  
      var val = req.session.user;
      res.render('home',{user:val});
  
  
  });
  </code></pre>
  
  <p>.ejs:</p>
  
  <pre><code>&lt;p&gt;
              您好！&lt;%= user.username %&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>But this is so troublesome.
  What is the better way to do it?</p>
  
  <p>(In php, I can just use $_SESSION to get the value in a view file.)</p>