npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

express-user-model

v0.1.1

Published

A user model setup for express and mongoose with basic features like email verification and so on

Readme

Express User Model

Build Status Coverage Status npm version

This is a library to provide a user backbone with basic requirements to start with. It assumes you are using mongoose with the driver for Mongoose. This plugin will add following fields to your User Model.

  • username
  • email
  • first_name
  • last_name

For password storage we recommend passport-local-mongoose with passport though you are free to use any required.

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install express-user-model

Usage

Create a user schema first and use the plugin as below.

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var EUM = require('express-user-model');

const UserSchema = new Schema({});
UserSchema.plugin(EUM);

Optionally, To add authentication and password fields, you can use passport-local as below.

const passportLocalMongoose = require('passport-local-mongoose');
UserSchema.plugin(passportLocalMongoose);

If you want to use Email verification and email management only , you can use the following code instead of whole EUM plugin as:

UserSchema.plugin(EUM.Email);

For basic features of first_name, last_name and username only, you can use as:

UserSchema.plugin(EUM.Basic);

Motivation

Coming from Django background, I thought of bringing all user related features to one place.

API Reference

Options:

You can pass options to the plugin as

UserSchema.plugin(EUM.Basic,options);

Main options:

  • usernameField:- Default username field to create ,Default value is username
  • usernameUnique:- Default value: true

Let us consider following scenario.

var user = new User({username: '12345'});

Basic:

Fields:

user.username = '12345'; 
user.first_name = 'Amrit';
user.last_name = 'Ghimire';

Methods:

user.full_name() // Returns the full name of user account (Amrit Ghimire)

Email

Fields:

user.emails = [{address:'',verified:false,token:''}]; // An array of subdocument each with address,verified and token
user.email = '' // To store primary email

Methods:

Add email:

user.addEmail(emailToAdd); // Add an email to user account
user.save(); 

Returns false if email already exists else return the email sub-document.

GetEmail:

var email = user.getEmail(email) // Get email object
// { address: ,verified: , token: }

Return email objects if exists

setPrimaryEmail

user.setPrimaryEmail(email); // Set email as primary key 

Sets email as primary email and it will throw an error if the email is not in users account. Will return new primary email otherwise.

getPrimaryEmail

user.getPrimaryEmail(); // Will return primary Email 

Primary key will be either the first email or the email set as primary key exclusively. Will return false if there is no primary key.

sendVerificationToken

user.sendVerificationToken(email, function (email, token) {
   console.log(email, 'Has token ', token, 'associated with it.') 
   // Replace this part with real email sending function. You can use any library to send email.
});

The call back function will be responsible for sending the token. The call back will receive parameter in one of these 3 formats.

  • email, token : In successful scenario
  • null, null : If email is already verified.
  • email, null : If email is not found or token is not found.

For verification of the token, use the middleware as:

app.get('verify/:token',EUM.Verify(User),function (req, res) {
                                           res.send('hello world');
});

Verify middleware is passed with the User Model. If the verification code cause some error, standard error is raised.

Tests

For development purpose, you can clone this repository and run test with following commands.

make test

You can view test.js file under test directory for some example usage of the library.

Contributors

All bugs, feature requests, pull requests, feedback, etc., are welcome. Create an issue.

License

This library is licensed under MIT License