Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongo connect npm

var express = require('express');
var session = require('express-session');
var MongoDBStore = require('connect-mongodb-session')(session);

var app = express();
var store = new MongoDBStore({
  uri: 'mongodb://localhost:27017/connect_mongodb_session_test',
  collection: 'mySessions'
});

// Catch errors
store.on('error', function(error) {
  console.log(error);
});

app.use(require('express-session')({
  secret: 'This is a secret',
  cookie: {
    maxAge: 1000 * 60 * 60 * 24 * 7 // 1 week
  },
  store: store,
  // Boilerplate options, see:
  // * https://www.npmjs.com/package/express-session#resave
  // * https://www.npmjs.com/package/express-session#saveuninitialized
  resave: true,
  saveUninitialized: true
}));

app.get('/', function(req, res) {
  res.send('Hello ' + JSON.stringify(req.session));
});

server = app.listen(3000);
Comment

PREVIOUS NEXT
Code Example
Javascript :: chart.js src 
Javascript :: see vuex values productin 
Javascript :: load data from json server into html using jquery 
Javascript :: vue js use component everywhere 
Javascript :: How to upload an Excel sheet file using react.js and display data to a table 
Javascript :: upgrading to react 18 
Javascript :: how to store object in session storage 
Javascript :: move last element of array to begining javascript 
Javascript :: Date object for local time and date 
Javascript :: Flatten a multidimension array 
Javascript :: add new database mongodb 
Javascript :: preventdefault javascript 
Javascript :: javascript add id to element with class 
Javascript :: ternary operator jquery 
Javascript :: fetch post js 
Javascript :: clear input field data in jquery 
Javascript :: anonymous function javascript 
Javascript :: angular build deploy url 
Javascript :: javascript find index 
Javascript :: select parent of elemt 
Javascript :: jquery dynamic event binding 
Javascript :: jquery: finding all the elements containing the text present in an array 
Javascript :: express.js hello world 
Javascript :: arrow functions 
Javascript :: settimeout method 
Javascript :: jquery selectors attribute ends with 
Javascript :: javascript dataset 
Javascript :: js sort by two numeric fields 
Javascript :: date without seconds react 
Javascript :: npm ERR! Error: connect ECONNREFUSED 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =