title: Nodejs express JWT how to strore and send token from web/phone client (jsonwebtoken)
body: <p>I'm using NodeJs with Express app to develop webs for browsers and mobile phones. I'm using JWT because it seems to be the standard and I read that sessions doesn't work well in phones (without browser). I have this code in the backend configured using "jsonwebtoken":</p>
  
  <pre><code>'use strict';
  
  const jwt = require('jsonwebtoken');
  const path = require('path');
  const fs = require('fs');
  const privateKEY  = fs.readFileSync(path.join(__dirname, 'private.key'), 'utf8');
  const publicKEY  = fs.readFileSync(path.join(__dirname, 'public.key'), 'utf8');
  
  module.exports = {
  
      sign: (payload) =&gt; {
          var signOptions = {
              expiresIn: process.env.TOKEN_EXPIRE_TIME,
              algorithm: "RS256"
          };
          return jwt.sign(payload, privateKEY, signOptions);
      },
  
      verify: (token) =&gt; {
          var verifyOptions = {
              expiresIn: process.env.TOKEN_EXPIRE_TIME,
              algorithm: ["RS256"]
          };
          try {
              return jwt.verify(token, publicKEY, verifyOptions);
          } catch (err) {
              return false;
          }
      },
  
      decode: (token) =&gt; {
          return jwt.decode(token, {
              complete: true
          });
      }
  
  };
  </code></pre>
  
  <p>But I don't know which is the way to implement the front end side. I need to know how to store the token for both devices (localStorage? sessionStorage? cookies? others?) and what could be a good way to make the links (href tag in html) sending the token from that storage method.</p>