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

gmail-imap

v0.0.2

Published

Easily access Gmail from your server-side node app

Readme

gmail-imap

Easily access your gmail account via node.

Uses oauth 2.0 to auth.

Installation

  1. Install npm: curl http://npmjs.org/install.sh | sh
  2. Grab this module from npm: npm install gmail-imap
  3. Include it in your program:
  • Coffeescript: Gmail = require 'gmail-imap'
  • Javascript: Gmail = require('gmail-imap');
  1. Create a project to retrieve a Client ID and Client Secret here: https://console.developers.google.com/project
  2. Create a configuration object to pass in:
var cfg = {
    CLIENT_ID: 'Your_client_id_here',
    CLIENT_SECRET: 'Your_client_secret_here'
};
  1. create a new instance of the gmail client:
  • Coffeescript: gmail = new Gmail cfg
  • Javascript: gmail = new Gmail(cfg);

Usage

  1. Get an Auth Url from google (requires clientId and clientSecret): var authUrl = gmail.getAuthUrl();
  2. Redirect the user to the Auth URL: res.redirect(authUrl) (if using Express)
  3. Get an access (and refresh) token from Google: gmail.getAccessToken(code, function(callback) {});
  4. If callback.access_token exists, get the user's e-mail: gmail.getEmail(callback.access_token, function(data) {});
  5. Create an xoauth2 token to pass to gmail: var xoauth2 = gmail.getXOauth2(data.email, callback.access_token);
  6. Now you have an xoauth2 token that you can pass to a library such as MailListener2.

Example

var Gmail = require('gmail-imap');

var cfg = {
    CLIENT_ID: 'Your_client_id_here',
    CLIENT_SECRET: 'Your_client_secret_here'
};

var gmail = new Gmail(cfg);

// Get gmail's authentication URL
var authUrl = gmail.getAuthUrl();

// redirect user to authUrl
res.redirect(authUrl);

gmail.getAccessToken(code, function(callback) {
  if(callback.access_token) {
    gmail.getEmail(callback.access_token, function(data) {
      res.send(data.emails[0].value);
    });
  }
});

Functions

Gmail (constructor)s - Create a Gmail object

  • Input: cfg (object)
  • Output: none
  • Example: var gmail = new Gmail({clientId: '1234', clientSecret: '5678'});

getAuthUrl - Get the authorization URL from google to redirect the user to authenticate

  • Input: none
  • Output: url (string)
  • Example: var authUrl = gmail.getAuthUrl();

getAccessToken - OAUTH2: Retrieves an access_token and refresh_token.

  • Input: code (from getauthUrl)
  • Output: json { access_token: 'aaaaa', refresh_token: 'bbbbb'}
  • Example: gmail.getAccessToken(code, function(callback) {});

getEmail - Get the user's e-mail address and profile information (Requires Access Token) Note: call this after getAccessToken!

  • Input: access_token
  • Output: json { 'uid': '124', emails: [ value: '[email protected]' ]}
  • Example: gmail.getEmail(access_token, function(callback) {});

getXOauth2 - Authenticate w/ Gmail's IMAP server (Requires Access Token/Email) Note: call this after getEmail!

  • Input: email, access_token
  • Output: json email object
  • Example: gmail.getXOauth2(email, access_token, function(data) {});

Help, I need an adult!

First step: Check out the /examples folder. It's decently documented.

If you're still having issues, you can submit them here: https://github.com/bdickason/node-goodreads/issues

Changelog

v0.0.1 - First release! Woohoo!!

  • Added support for an OAuth2 round trip via access_token and refresh_token
  • Added support for generating an xoauth2 token
  • Started this ugly manual