# prettiest

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

Latest version **1.1.0** (published 2020-01-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install prettiest
pnpm add prettiest
yarn add prettiest
bun add prettiest
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2020-01-04 |
| First published | 2014-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 78 |
| Author | P'unk Avenue LLC |
| Maintainers | alexgilbert, benirose, boutell, colpanik, jimmyh, jsumnersmith, kylestetz, livhaas, mcoppola, stuartromanek, suhmantha1 |
| Keywords | lock, database, simple, database, shell, scripts, shelljs |

## Links

- npm: https://www.npmjs.com/package/prettiest
- Repository: https://github.com/punkave/prettiest
- Issues: https://github.com/punkave/prettiest/issues
- npm.io page: https://npm.io/package/prettiest

## Dependencies (1)

- [fs-ext](https://npm.io/package/fs-ext.md) ^2.0.0

## Alternatives

- [@oh-my-pi/pi-natives](https://npm.io/package/@oh-my-pi/pi-natives.md) — 51.8K weekly downloads
- [@capgo/capacitor-light-sensor](https://npm.io/package/@capgo/capacitor-light-sensor.md) — 3.0K weekly downloads
- [@heyhuynhgiabuu/pi-diff](https://npm.io/package/@heyhuynhgiabuu/pi-diff.md) — 492 weekly downloads
- [@lotsa/verdant-lang-asm](https://npm.io/package/@lotsa/verdant-lang-asm.md) — 38 weekly downloads
- [new-era-syntax](https://npm.io/package/new-era-syntax.md) — 20 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2020-01-04
- 1.0.0 — 2016-01-11
- 0.1.0 — 2014-12-19

## README

# prettiest

```javascript
// 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](http://documentup.com/arturadib/shelljs).

## Install

`npm install prettiest`

## Options

You can specify where the JSON data file lives:

```javascript
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](https://apostrophecms.com).

## 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.

---
_Source: https://npm.io/package/prettiest · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
