How to use connect-mongo - 10 common examples

To help you get started, we’ve selected a few connect-mongo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github freeCodeCamp / meeting-for-good / server / app.js View on Github external
app.use(webpackHotMiddleware(compiler, {
    log: console.log,
    path: '/__webpack_hmr',
    heartbeat: 2000,
  }));

  app.use(session({
    secret: 'secretClementine',
    resave: false,
    saveUninitialized: true,
  }));
} else {
  // Production Env Production Specific stuff
  // - Use MongoStore instead of MemoryStore for the session
  const MongoStore = connectMongo(session);
  app.use(session({
    secret: 'secretClementine',
    resave: false,
    saveUninitialized: true,
    store: new MongoStore({ mongooseConnection: mongoose.connection }),
  }));
  // setup the logger
  app.use(morgan(':status :method :response-time ms - :url'));
}

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

require('./app/config/passport')(passport);

app.use(passport.initialize());
github lala010addict / Rich-Neighbors / server / config / express.js View on Github external
import express from 'express';
import favicon from 'serve-favicon';
import morgan from 'morgan';
import compression from 'compression';
import bodyParser from 'body-parser';
import methodOverride from 'method-override';
import cookieParser from 'cookie-parser';
import errorHandler from 'errorhandler';
import path from 'path';
import lusca from 'lusca';
import config from './environment';
import passport from 'passport';
import session from 'express-session';
import connectMongo from 'connect-mongo';
import mongoose from 'mongoose';
var mongoStore = connectMongo(session);

module.exports = function(app) {
  var env = app.get('env');

  app.set('views', config.root + '/server/views');
  app.engine('html', require('ejs').renderFile);
  app.set('view engine', 'html');
  app.use(compression());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(bodyParser.json());
  app.use(methodOverride());
  app.use(cookieParser());
  app.use(passport.initialize());

  // Persist sessions with mongoStore / sequelizeStore
  // We need to enable sessions for passport-twitter because it's an
github patrickrb / edGalaxyMap / server / config / express.js View on Github external
import express from 'express';
import favicon from 'serve-favicon';
import morgan from 'morgan';
import compression from 'compression';
import bodyParser from 'body-parser';
import methodOverride from 'method-override';
import cookieParser from 'cookie-parser';
import errorHandler from 'errorhandler';
import path from 'path';
import lusca from 'lusca';
import config from './environment';
import passport from 'passport';
import session from 'express-session';
import connectMongo from 'connect-mongo';
import mongoose from 'mongoose';
var mongoStore = connectMongo(session);

module.exports = function(app) {
  var env = app.get('env');

  app.set('views', config.root + '/server/views');
  app.engine('html', require('ejs').renderFile);
  app.set('view engine', 'html');
  app.use(compression());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(bodyParser.json());
  app.use(methodOverride());
  app.use(cookieParser());
  app.use(passport.initialize());

  // Persist sessions with mongoStore / sequelizeStore
  // We need to enable sessions for passport-twitter because it's an
github nerdeveloper / hackathon-starter-kit / src / app.ts View on Github external
import mongo from "connect-mongo";
import path from "path";
import flash from "connect-flash";
import compression from "compression";
import cors from "cors";
import helmet from "helmet";
import errorHandler from "errorhandler";

dotenv.config({path: "variable.env"});
import indexRouter from "./routes/index";
import authRouter from "./routes/auth";
import "./handlers/passport";

// import environmental variables from our variables.env file

const MongoStore = mongo(session);
// Create Express server
const app = express();

app.use(helmet());
// view engine setup
app.set("views", path.join(__dirname, "../views")); // this is the folder where we keep our pug files
app.set("view engine", "pug"); // we use the engine pug, mustache or EJS work great too
app.get("env") === "development" ? app.use(require("express-status-monitor")()) : "";
app.use(logger("dev"));
app.use(compression());
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(cors());

// serves up static files from the public folder. Anything in public/ will just be served up as the file it is
app.use(express.static(path.join(__dirname, "../public")));
github gaoxiaoliangz / readr / src / server / initialize.ts View on Github external
import morgan from 'morgan'
import cookieParser from 'cookie-parser'
import bodyParser from 'body-parser'
import connectMongo from 'connect-mongo'
import graphQLHTTP from 'express-graphql'
import render from './middleware/render'
import bootServer from './bootstrap'
import apiApp from './api/app'
import getMongoDBUrl from './helpers/getMongoDBUri'
import middleware from './middleware'
import schema from './graphql/schema'
import { SESSION_SECRET, REQ_SIZE_LIMIT, PUBLIC_URL, PUBLIC_DIR, COOKIE_MAX_AGE } from './constants'

const debug = require('debug')('readr:init')

const MongoStore = connectMongo(session)
const app = express()

interface InitConfig {
  basePath: string
}

export default function initialize(config: InitConfig) {
  debug('app init')
  const { basePath } = config

  // locals
  app.locals.basePath = basePath

  app.use(session({
    secret: SESSION_SECRET,
    resave: true,
github Data4Democracy / ati-broadcastapp / server / routes / index-wrapper.js View on Github external
export default async function getRouter() {
  const config = await getConfigPromise();
  await getDbConnection();

  const router = express.Router();

  // app.use(cookieParser());

  // set up session store
  const MongoStore = connectMongo(expressSession);
  router.use(expressSession({
    secret: config.get('cookiesecret'),
    //  some options should be set when on GAE
    secure: config.get('is_gae'),
    cookie: { sameSite: true },
    saveUninitialized: false,
    // resave and touchAfter go together. resave specifies if the session
    // info is always resaved, even if unchanged. touchAfter (as best I can
    // tell) means how often to resave the session info even if nothing has
    // changed (and is given in seconds)
    resave: false,
    //  use default connection
    store: new MongoStore({
      mongooseConnection: mongoose.connection,
      touchAfter: 24 * 3600,
    }),
github Data4Democracy / ati-broadcastapp / server / routes / index.js View on Github external
export default async function getRouter() {
  const config = await getConfigPromise();
  await getDbPromise();

  const router = express.Router();

  // app.use(cookieParser());

  // set up session store
  const MongoStore = connectMongo(expressSession);
  // comments about options:
  // secure: some options should be set when on GAE
  // resave: resave and touchAfter go together. resave specifies if the
  //   session info is always resaved, even if unchanged. touchAfter (as
  //   best I can tell) means how often to resave the session info even if
  //   nothing has changed (and is given in seconds)
  //  store: use default connection
  router.use(expressSession({
    secret: config.get('cookiesecret'),
    secure: config.get('is_gae'),
    cookie: { sameSite: true },
    saveUninitialized: false,
    resave: false,
    store: new MongoStore({
      mongooseConnection: mongoose.connection,
      touchAfter: 24 * 3600,
github alphalion-tool / react-crm-kit / server / server.js View on Github external
function connect() {
    var options = {
        useNewUrlParser: true
    };
    return mongoose.connect(appConfig.db, options);
}

const app = express();
const indexController = require('./controller/indexController');
const hubController = require('./controller/').hubController;
const authMiddleware = require('./middlewares/auth').authMiddleware;

const staticPath = path.join(__dirname, '../build/static');
const templatePath = path.join(__dirname, '../build/templates');

const MongoStore = connectMongo(session);

app.set('views', templatePath);
app.set('view engine', 'pug');
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
    extended: true
}));

app.use(session({
    resave: true,
    saveUninitialized: true,
    secret: 'bitbal',
    store: new MongoStore({
        url: appConfig.db,
        collection: 'sessions'
github pairhub / pairhub / api / auth.js View on Github external
bio: profile._json.bio,
        avatar_url: profile.photos[0].value,
        github_url: profile.profileUrl,
        email: (profile.emails && profile.emails[0].value) || null,
        seenWelcomeModal: false,
      })
        .save()
        .then(result => done(null, result));
    });
  }));

  passport.serializeUser((user, done) => done(null, user._id));

  passport.deserializeUser((_id, done) => User.findOne({ _id }).then(user => done(null, user)));

  const MongoStore = connectMongo(session);

  app.use(session({
    secret: process.env.SESSION_SECRET,
    store: new MongoStore({ mongooseConnection: mongoose.connection }),
    resave: true,
    saveUninitialized: true,
  }));

  app.use(passport.initialize());
  app.use(passport.session());

  app.get('/login/github', passport.authenticate('github'));

  app.get(
    '/login/github/callback',
    passport.authenticate('github', { failureRedirect: '/' }),

connect-mongo

MongoDB session store for Express and Connect

MIT
Latest version published 1 year ago

Package Health Score

68 / 100
Full package analysis

Popular connect-mongo functions