All Projects → mjbondra → koa-session-mongoose

mjbondra / koa-session-mongoose

Licence: MIT license
Mongoose store for Koa sessions

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to koa-session-mongoose

Kov Blog
A blog platform built with koa,vue and mongoose. 使用 koa ,vue 和 mongo 搭建的博客页面和支持markdown语法的博客编写平台,自动保存草稿。博客地址:https://chuckliu.me
Stars: ✭ 635 (+2089.66%)
Mutual labels:  mongo, koa, mongoose
graceful
Gracefully exit server (Koa), database (Mongo/Mongoose), Redis clients, and job scheduler (Redis/Bull)
Stars: ✭ 37 (+27.59%)
Mutual labels:  mongo, koa, mongoose
Spruce
A social networking platform made using Node.js and MongoDB
Stars: ✭ 399 (+1275.86%)
Mutual labels:  mongo, mongoose
Mean Angular4 Chat App
MEAN stack with Angular 4 Chat App
Stars: ✭ 41 (+41.38%)
Mutual labels:  mongo, mongoose
Node Typescript Mongodb
node js typescript mongodb express generator yo
Stars: ✭ 96 (+231.03%)
Mutual labels:  mongo, mongoose
mongoose-auto-increment-reworked
An auto-incrementing field generator for Mongoose 4 & 5
Stars: ✭ 17 (-41.38%)
Mutual labels:  mongo, mongoose
node-express-mongo-passport-jwt-typescript
A Node.js back end web application with REST API, user JWT authentication and MongoDB data storage using TypeScript
Stars: ✭ 51 (+75.86%)
Mutual labels:  mongo, mongoose
Mongoose Fuzzy Searching
Mongoose Fuzzy Searching Plugin
Stars: ✭ 94 (+224.14%)
Mutual labels:  mongo, mongoose
react-full-stack-starter
🎈Full-stack React boilerplate using `create-react-app`, Babel, Node.js, and express
Stars: ✭ 22 (-24.14%)
Mutual labels:  mongo, mongoose
Mern Passport
A boilerplate example of using passport.js for authenticating a MERN application
Stars: ✭ 214 (+637.93%)
Mutual labels:  mongo, mongoose
Nest User Auth
A starter build for a back end which implements managing users with MongoDB, Mongoose, NestJS, Passport-JWT, and GraphQL.
Stars: ✭ 145 (+400%)
Mutual labels:  mongo, mongoose
nestjs-api-mongoose
Collection example apps with NestJS and Typeorm, Sequelize, Mongodb, PostgreSQL, MySQL, GraphQL, Mercurius, etc. for the NestJS community 😻
Stars: ✭ 153 (+427.59%)
Mutual labels:  mongo, mongoose
Registration-and-Login-using-MERN-stack
Simple Registration and Login component with MERN stack
Stars: ✭ 210 (+624.14%)
Mutual labels:  mongo, mongoose
authentication boilerplate
A Node based Boilerplate for register, login, request password reset password. Using Sengrid to send emails
Stars: ✭ 19 (-34.48%)
Mutual labels:  mongo, mongoose
ark.db
Small and fast JSON database for Node and browser. 😋
Stars: ✭ 65 (+124.14%)
Mutual labels:  mongo, mongoose
Mean Stack Angular6 Crud Example
MEAN Stack Angular 6 CRUD Web Application
Stars: ✭ 69 (+137.93%)
Mutual labels:  mongo, mongoose
mongoolia
Keep your mongoose schemas synced with Algolia
Stars: ✭ 58 (+100%)
Mutual labels:  mongo, mongoose
nutri.gram
Nutrition is the main source of life and although it has been our secondary instinct to check for nutritional value in the food we eat, the effect any diet has on our body and health is consequential. From the fact which connotes the value of nutrition in our diet, springs the idea of nutri.gram. nutri.gram is a mobile application that scans the…
Stars: ✭ 21 (-27.59%)
Mutual labels:  mongo, mongoose
Intro Mongo Db
[Course] Introduction to MongoDB code
Stars: ✭ 114 (+293.1%)
Mutual labels:  mongo, mongoose
koa-mongoDB
😊😊Koa and mongoose build services
Stars: ✭ 24 (-17.24%)
Mutual labels:  koa, mongoose

koa-session-mongoose

Mongoose storage layer for koa-session.

Installation

npm i --save koa-session-mongoose

OR

yarn add koa-session-mongoose

Usage

Prerequisites

This store requires node@>=8.3.0, koa@>=2.0.0, and koa-session@>=5.0.0.

It has a peer-dependency of mongoose@>=5.0.0.

If you are using older dependencies, consider using koa-session-mongoose@^1.0.0 or koa-session-mongoose@^2.0.0.

Code Examples

const Koa = require("koa");
const mongoose = require("mongoose");
const MongooseStore = require("koa-session-mongoose");
const session = require("koa-session");

// mongoose connection must exist before creating a store with koa-session-mongoose
mongoose.connect("mongodb://some_host/some_db");

const app = new Koa();

// needed for cookie-signing
app.keys = ["some secret key"];

app.use(session({ store: new MongooseStore() }, app));

app.use(async ctx => {
  const { session } = ctx;
  let n = session.views || 0;
  session.views = ++n;
  ctx.body = `${n} view(s)`;
});

app.listen(3000);

You can optionally specify collection name (collection), model name (name), expiration time in seconds (expires), and Mongoose connection (connection):

async function init (uri) => {
  const connection = await mongoose.connect(uri, {
    useCreateIndex: true,
    useFindAndModify: false,
    useNewUrlParser: true,
    useUnifiedTopology: true
  });

  app.use(session({
    store: new MongooseStore({
      collection: 'appSessions',
      connection: connection,
      expires: 86400, // 1 day is the default
      name: 'AppSession'
    })
  }, app));
}

Related Modules

Development

Merge requests should be submitted to https://gitlab.com/wondermonger/koa-session-mongoose.

A mirror of the project will persist at https://github.com/mjbondra/koa-session-mongoose, but all future development will be directed to the new repository.

Installation

npm i

Linting

npm run lint

Testing

# all tests
npm run test

# integration tests
npm run test:integration

# unit tests
npm run test:unit

If you require a MongoDB URI other than the default (mongodb://127.0.0.1/koa-session-mongoose), specify it as follows before executing npm run test or npm run test:integration:

MONGODB_URI="mongodb://[username:password@]host[:port]/[database]"

License

The MIT License (MIT)

Copyright (c) 2013-2019 Michael J. Bondra [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].