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

@nodepack/plugin-passport

v0.9.0

Published

Auth Nodepack plugin using Passport

Readme

Passport plugin for Nodepack

nodepack add passport

Tutorial

In this tutorial we will manually implement a Google OAuth 2.0 strategy to authenticate our users.

Setup

Start by creating a Typescript + Express application with nodepack create.

Then, in the project, install the relevant google oauth package:

yarn add passport-google-oauth20

Let's also create a new passport.ts file where we will setup our Google OAuth:

// src/passport.ts

import { useStrategy, deserializeUser } from '@nodepack/plugin-passport'
import { Strategy as GoogleStrategy } from 'passport-google-oauth20'
import { ExpressContext } from '@nodepack/plugin-express'
import passport from 'passport'

// Usage storage where you would usually use a database
const users: { [key: string]: any } = {}

const googleStrategy = new GoogleStrategy({
  clientID: process.env.GOOGLE_CLIENT_ID,
  clientSecret: process.env.GOOGLE_CLIENT_SECRET',
  callbackURL: 'http://localhost:4242/passport/google/callback',
}, (accessToken, refreshToken, profile, done) => {
  // Create or update user account
  users[profile.id] = {
    ...profile,
    accessToken,
    refreshToken,
  }
  done(null, profile)
})

useStrategy(googleStrategy, (ctx: ExpressContext) => {
  // Setup google oauth routes
  const { express: app } = ctx
  app.get('/passport/google', passport.authenticate('google', {
    scope: ['profile'],
  }))
  app.get('/passport/google/callback', passport.authenticate('google', {
    failureRedirect: '/login',
  }), (req, res) => {
    res.redirect('/')
  })
})

deserializeUser((ctx, { serialized }) => {
  // You would usually do a database request
  return users[serialized]
})

Import the file in your entry point:

// src/index.ts

import './passport'

Create a .env.local file at the project root to setup our environment variables (you'll need to get them from your Google Developer Console):

GOOGLE_CLIENT_ID=xxxxxxxxxxxxxxxx
GOOGLE_CLIENT_SECRET=xxxxxxxxxxxxxxxx
COOKIE_SECRET=xxxxxxxxxxxxxxxxx

Don't forget to add http://localhost:4242/passport/google/callback to the callback URLs on the Google Developer Console.

For COOKIE_SECRET, you can generate a random secret at https://duckduckgo.com/?q=uuid.

Finally, setup the session cookies by creating a config/cookie.ts file:

// config/cookie.ts

// Cookie config
// See: https://github.com/expressjs/cookie-session#options

export default {
  secret: process.env.COOKIE_SECRET,
}

The setup is now complete!

Usage in app

Run the app with:

PORT=4242 nodepack

Navigate to http://localhost:4242/passport/google to sign in using your Google account.

You can use req.user in an Express context. For example, here a route that render the user profile:

// src/routes/profile.ts

import { ExpressContext } from '@nodepack/plugin-express'
import profile from '@/views/profile.ejs'

export default function ({ express: app }: ExpressContext) {
  app.get('/profile', (req, res) => {
    res.send(profile({ user: req.user }))
  })
}

With the following EJS view:

<!-- src/views/profile.ejs -->

<p>
  ID: <%= user.id %><br/>
  Name: <%= user.displayName %><br/>
  <% if (user.emails) { %>
  Email: <%= user.emails[0].value %><br/>
  <% } %>
</p>