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 🙏

© 2024 – Pkg Stats / Ryan Hefner

redistoken

v1.0.1

Published

A package to generate tokens to store temporary data in redis

Downloads

4

Readme

Store data in redis under a random key

Generates a random token to store some data under in redis. Things that this module can be used for:

  • Saving session data
  • Generating a token for use in email verification
  • Saving flash messages

This module was made after having to do very similar things multiple times in the web applications I work on. Mostly these are related to user management actions, like the email verification link or single use login tokens for mobile apps.

Install

$ npm install --save redistoken

Usage

var RedisToken = require('redistoken');

// Create a data store
var dataStore = new RedisToken({
	prefix: 'mydata'
});

// Set a key
dataStore.set('data', function(err, token) {
	if (err) {
		return console.log(err);
	}

	// Give the token to whoever is going to 
	// fetch this data in the future, usually either 
	// as a browser cookie or in the response body 
	// for an api.
	
});

// Get the data
dataStore.get(token, function(err, data) {
	if (err) {
		return console.log(err);
	}

	console.log(data); // 'data'
});

Options

All options below are showing their default values.

var dataStore = new RedisToken({
	redisPort: undefined, // The redis server port
	redisHost: undefined, // The redis server host
	redisOpts: {}, // The redis server connection options
	prefix: '', // Key prefix
	expires: 60, // Key expiration
	onReady: noop, // Redis connection events
	onConnect: noop,
	onError: noop,
	strongKey: false, // Should it generate a cryptographically secure key
	len: 16, // The length of the generated token
	singleUse: true, // Delete the key after successful get
	stringifyData: true, // JSON stringify the data before saving, parse on get
});

Tests

$ npm test
$ REDIS_HOST="192.168.59.103" REDIS_PORT="6370" mocha

The test are run with mocha and use a docker container to run redis. On my machine I run docker in boot2Docker, which starts on 192.168.59.103. You can see this IP in the package.json, edit this to suite your environment. To run these tests you will need to setup boot2docker and run npm run docker-redis-pull once before getting started. Optionally you can just run mocha directly with the second command above.