forked from adatechschool/projetmeubles_back_MJSQE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.js
53 lines (40 loc) · 1.29 KB
/
session.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//$ SESSIONS $
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// https://fr.acervolima.com/gestion-de-session-a-l-aide-du-module-de-session-express-dans-node-js/
// TUTO EN LIGNE : session.js
const express = require("express")
const session = require('express-session')
const app = express()
// Port Number Setup
var PORT = process.env.port || 4000
// Session Setup
app.use(session({
// It holds the secret key for session
secret: 'petitePrince$$',
// Forces the session to be saved
// back to the session store
resave: true,
// Forces a session that is "uninitialized"
// to be saved to the store
saveUninitialized: true
}))
app.get("/", function(req, res){
// req.session.key = value
req.session.name = 'userSession'
return res.send("Session Set")
})
app.get("/session", function(req, res){
var name = req.session.name
return res.send(name)
/* To destroy session you can use
this function
req.session.destroy(function(error){
console.log("Session Destroyed")
})
*/
})
app.listen(PORT, function(error){
if(error) throw error
console.log("Server created Successfully on PORT :", PORT)
})