How to do authentication with Node.js, Express and Mongoose?


I've made simple nodejs application by using nodejs+express. Now I want to make user authentification. I want to realize session handling by using mongoose. Can you advise some example?

12/6/2011 10:05:27 AM

Accepted Answer

Some useful links:

how to implement login auth in node.js

creating registration and login form in node.js and mongodb

Also session management isn't done by Mongoose, but by connect-mongodb or connect-redis. You can checkout an example on how to do user auth and session management in a real application here:

Further explanations for that app you can find here: or

5/23/2017 12:33:59 PM

Just use mongoose-auth by Brian Noguchi

It's a drop in solution for your question, it's well documented and extensible.


mongoose-auth is no longer maintained. If you need to make it work with more recent versions of mongoose (ie > v3.x.x) and express (ie. > v3.x.x), here's an excerpt from a package.json file I'm currently using in production (It's hacky but it works):

"everyauth": "",
"mongoose-3x-types": "~1.0.5",
"mongoose-auth": "",

I you are starting a new project don't use mongoose-auth, instead try out passport. It offers the same functionality, it's very flexible, however it has a different api. It's part of the locomotive MVC framework and as such it's actively maintained.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow