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

cwhite-gmail-watcher

v0.1.7

Published

A simple yet functional email processor written in NodeJS!

Readme

GmailWatcher

A simple yet functional email processor written in NodeJS!

NOTE: You will need to use an "app password" for gmail. [More info]

Usage

const GmailWatcher = require('cwhite-gmail-watcher');

The inline doc from the class:

/**
 * Generic interface to process emails from GMail using IMAP filters & body regex parsing.
 * Once messages are processed, they are marked as read and moved to a designated folder
 * 
 * Calls `parseFunc` to turn emails into objects and `insertCallback` on successful parsing.
 * Example settings object:
 *  {
 *       username: '[email protected]',
 *       password: 'password123',
 *       keepEmail: true,               // optional. If true, the emails will not be moved upon succesful processing
 *       targetDomain: 'example.com',   // the domain you should be receiving these emails from. This is used to verify certificates
 *       outputFolder: 'myEmails',
 *       imapFilters: [
 *           ['FROM', '@mydomain.com'],
 *           ['SUBJECT', 'Daily Mail']
 *       ],
 *  }
 */

Example

This is how I save my Credit Card transactions in AWS Lambda!
(Anything marked as HIDDEN has been removed as I consider it sensitive)
(I wish I could have used Mongo Atlas Functions, but they ran into issues with IMAP)

Truncated Version:

import GmailWatcher from "cwhite-gmail-watcher";
import { MongoClient, ServerApiVersion } from 'mongodb';

const txnRegex = RegExp("[HIDDEN]");
const uri = `[HIDDEN]`;

function parseTxn({ messageId, text, date }) { /* ... */ }

export const handler = event => {
  const mongoClient = // ...

  const g = new GmailWatcher(
    {
      username: '[HIDDEN]',
      password: process.env.GOOGLE_APP_PASSWORD,
      targetDomain: "[HIDDEN]",
      keepEmail: true,
      outputFolder: "[HIDDEN]",
      imapFilters: [
        ['FROM', '@[HIDDEN]'],
        ['SUBJECT', '[HIDDEN]']
      ],
    },
    parseTxn,
    txn => {
      return mongoClient
        .db("[HIDDEN]")
        .collection("[HIDDEN]")
        .insertOne(txn)
    },
  );

  mongoClient.connect().then(() => { /* ... */ }).catch(err => { /* ... */ });
}

Full version:

import GmailWatcher from "cwhite-gmail-watcher";
import { MongoClient, ServerApiVersion } from 'mongodb';

const txnRegex = RegExp("[HIDDEN]");
const uri = `[HIDDEN]`;

function parseTxn({ messageId, text, date }) {
  let res = txnRegex.exec(text);
  if (!res) {
    return { txn: null, parseErr: true };
  }

  const cardName = res[1];
  const cardNumberSuffix = res[2];
  const dollars = res[3] === '' ? 0 : Number(res[3]);
  const cents = Number(res[4]);
  const merchant = res[5];

  const amount = dollars + (cents / 100);

  return {
    txn: {
      _id: messageId,
      cardName,
      cardNumberSuffix,
      timestamp: date,
      amount,
      merchant
    },
    parseErr: false
  };
}

export const handler = event => {
  const mongoClient = new MongoClient(uri, {
    serverApi: {
      version: ServerApiVersion.v1,
      strict: true,
      deprecationErrors: true,
    }
  });

  const g = new GmailWatcher(
    {
      username: '[HIDDEN]',
      password: process.env.GOOGLE_APP_PASSWORD,
      targetDomain: "[HIDDEN]",
      keepEmail: true,
      outputFolder: "[HIDDEN]",
      imapFilters: [
        ['FROM', '@[HIDDEN]'],
        ['SUBJECT', '[HIDDEN]']
      ],
    },
    parseTxn,
    txn => {
      return mongoClient
        .db("[HIDDEN]")
        .collection("[HIDDEN]")
        .insertOne(txn)
    },
  );

  mongoClient.connect().then(() => {
    try {
      g.run(async () => {
        await mongoClient.close();
      });
    } catch (err) {
      console.log("cwhite: General Error");
      console.log(err.stack)
      throw err;
    }

  }).catch(err => {
    console.log("cwhite: Error connecting to MongoDB");
    console.log(err.stack)
    throw err;
  });
}