Node JS Tutorial in Hindi #62 - Session
Set and Get Session in Node js
Points of this video
- What are Session?
- Install Session npm package
- Set Session.
- Check Session are stored or not.
- Display Session data on UI
- Interview Questions
- Notes, Code and playlist.
What is Session?
- Store Data on server
- More secure
- Key stored in cookies
index.js file code
import express from 'express'
import session from 'express-session';
const app = express();
app.set("view engine", 'ejs')
app.use(session({
secret:'apple',
}))
app.use(express.urlencoded({ extended: true }))
app.get("/login", (req, resp) => {
resp.render('login')
})
app.post("/profile",(req,reps)=>{
req.session.data= req.body;
console.log(req.session.data);
reps.render('profile')
})
app.get("/",(req,resp)=>{
const data = req.session.data;
console.log("data",data);
resp.render("home",{data})
})
app.listen(3200)
Code Link:- https://github.com/anil-sidhu/node-express-mongodb/tree/session