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

prettiest

v1.1.0

Published

Incredibly simple data storage and locking for command line scripts. Pairs nicely with shelljs and a nice chianti.

Downloads

45

Readme

prettiest

// The simplest script: keeps track of how many
// times it has been run. It's like magic!

var data = require('prettiest')();

data.count = data.count || 0;
data.count++;
console.log('I have been run ' + data.count + ' times.');

prettiest provides simple command line apps with two important features:

  1. Persistent data. Any changes made to the data object returned by prettiest are automatically saved when the app exits.

  2. Concurrency locks. If two copies of your app start at the same time, the second one will always wait for the first one to finish before it proceeds.

If you're replacing a shell script with something a little smarter, this module is a great companion for shelljs.

Install

npm install prettiest

Options

You can specify where the JSON data file lives:

var data = require('prettiest')({ json: __dirname + '/mydatafile.json' });

If you don't, the JSON file lives in the same directory with your app, and will be called data.json.

prettiest also creates a lock file, which will have the same name as the JSON file, plus .lock at the end. To prevent race conditions, the lock file is not removed. Just leave it be.

Caveats

  • The save-and-unlock behavior lives in a process.on('exit') handler. Which is great, actually, but just bear in mind it won't fire if node itself crashes. In which case your data object probably isn't ready to save anyway, right?

  • You don't want to use this in a web application. Duh. It's a simple, synchronous bit of magic for use in utilities with short execution times.

  • You don't want to use this in a super-long-running script, because it only saves your data to disk at the very end. It's meant for utilities that do a relatively simple job and then exit.

Questions

  • "Can my code still be asynchronous?" Sure, knock yourself out. The save-and-unlock logic runs when your code exits.

Credits

prettiest was built for ApostropheCMS.

Changelog

1.1.0: dependency on fs-ext bumped to 2.0.0, in hopes of smoother cross-platform compilation than with the prereleases. Moved to const and let since they are supported back to well before currently supported versions of node.

1.0.0: accepted pull request to use newer fs-ext because of compilation issues on newer systems. Thanks to Kerrick. Bumped to 1.0.0 stable. Now following semver.

0.1.0: initial release.