search

Home  >  Q&A  >  body text

node.js - node express how to get client cookie

The user enters the domain name. If he has logged in before, he will go directly to the homepage. Otherwise, he will jump to the login interface because after logging in, I save the username in the cookie. Now I want to use cookies to determine if the user is logged in or not.

ringa_leeringa_lee2701 days ago1040

reply all(1)I'll reply

  • typecho

    typecho2017-06-24 09:45:18

    Introducing the cookie-parser package.

    const app = express();
    ...
    const cookieParser = require('cookie-parser');
    app.use(cookieParser());
    ...
    

    Then you should be able to use req.cookies in the routing to get the cookie object

    reply
    0
  • Cancelreply