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 🙏

© 2025 – Pkg Stats / Ryan Hefner

fortunes

v0.0.3

Published

Interface to the fortunes installed on Ubuntu.

Readme

Fortunes

Interface to the fortune package installed on Linux (tested against Ubuntu 12.04).

Provides a simple interface to the fortune program and data in Linux. Allows for searching for fortunes based upon:

  • search term
  • short fortunes or not
  • specific categories

Also allows the maximum number of fortunes returned to be specified.

Prerequisites

The fortune program needs to be installed in order for this module to work because this module uses spawn to run the fortune program in order to get the data.

On Ubuntu, you install it like this:

sudo apt-get install fortune-mod

Installation

npm install fortunes

Usage

var fortunes = require('fortunes');
var options = {
    isShort: true,
    max: 5,
    term: 'men',
    categories: ['computers', 'love', 'people']
};
fortunes.search(function(results) {
    // default options are used
});
fortunes.search(options, function(results) {
    // do something with the results which are an array of strings
});
fortunes.random(function(fortune) {
    // default options, only one result (string) is returned
});
fortunes.random(options, function(fortune) {
    // options specified but still only one result (string) is returned
});

API

search

Parameters:

  • options: optional object specifying search options.
  • callback: non-optional callback.

Valid options are:

  • term: the word to search for (case-insensitive search using white-space delimiter)
  • max: the maximum number of fortunes to return
  • isShort: whether only short fortunes are returned. "Short" is based upon the fortune program implementation (Ubuntu Linux fortune-mod package is 160 characters maximum).
  • categories: an array of strings corresponding to the fortune categories to use. These correspond to the various files in the fortune data directory.

Default options are:

  • term: ''
  • max: 10
  • isShort: false
  • categories: [] (which means all categories)

random

The random() function is sugar for the search() function. Parameters and valid options are the same as for search with the exception that max is always 1 and cannot be over-ridden.

Note that an array is not returned for random(). Instead, a string containing the one fortune is returned.

Testing

mocha test/test.index.js

Purpose

I personally needed a module that would provide me data for some other testing of some client-side applications. Using fortunes seemed like a reasonably interesting idea with lots of data to search and use. Your mileage may vary.

Future

The current implementation uses spawn to interface with the fortune program which means that the fortune program needs to be installed as a prerequisite. I don't have any plans to change this right now because it meets my needs and it was the path of least resistance. But it would be nice to not have this dependency.