nodejs express session:
nodejs is the best platform to create the scalable, fast and flexible application. session variable used every application to flexible the programme.so uses is the sample.
just simply install the module.
now importing the module like that,
var session = require('express-session');
app.use(session({ secret: "Shh, its a secret!" }));
and used in your rest API as below,
app.get('/', (req, res) => {
if (req.session.accessToken == null) {
res.redirect('/login')
} else if (req.session.accessToken != null) {
app.use(express.static(path.join(__dirname, 'build')));
res.json({ success: true, msg: 'user registered' });
res.sendFile(__dirname, path.join('build/index.html'));
}
res.json({ success: true, msg: 'user registered' });
});
simple way to check session varible in nodejs

0 Comments