-
Notifications
You must be signed in to change notification settings - Fork 342
/
Copy pathmongoose.js
34 lines (29 loc) · 817 Bytes
/
mongoose.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
const express = require('express')
const session = require('express-session')
const MongoStore = require('connect-mongo')
const mongoose = require('mongoose');
const app = express()
const port = 3000
const clientP = mongoose.connect(
'mongodb://root:[email protected]:27017',
{ useNewUrlParser: true, useUnifiedTopology: true }
).then(m => m.connection.getClient())
app.use(session({
secret: 'foo',
resave: false,
saveUninitialized: false,
store: MongoStore.create({
clientPromise: clientP,
dbName: "example-db-mongoose",
stringify: false,
autoRemove: 'interval',
autoRemoveInterval: 1
})
}));
app.get('/', (req, res) => {
req.session.foo = 'test-id'
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})