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

fraud

v5.2.1

Published

[![NPM](https://img.shields.io/npm/v/fraud.svg)](https://www.npmjs.com/package/fraud) [![Build](https://img.shields.io/travis/AnandChowdhary/fraud.svg)](https://travis-ci.org/AnandChowdhary/fraud) [![Coveralls](https://img.shields.io/coveralls/github/Anan

Downloads

58

Readme

🗄 Fraud

NPM Build Coveralls Type definitions GitHub Vulnerabilities

Fraud is a promise-based library for Node.js for a data storage solution for times when MongoDB is an overkill. It's essentially a wrapper around the native fs filesystem and nodecache, with added utilities.

⭐ How it works

Add fraud to your project with NPM:

npm install fraud

Add it to your project:

const Fraud = require("fraud");

Initialize it with the directory of your database:

const database = new Fraud({
    directory: "./database"
});

Now, you can use Fraud functions to use your file system as a JSON database. This is much faster then querying MongoDB in use cases where you only search for the primary key (in this case, the file name).

💡 Why Fraud

  • No-config database for key-JSON storage
  • Caches everything in memory, uses file system if uncached
  • Super fast and super low-latency

Real use case: Switching API configuration from MySQL (managed RDS in the same region as an EC2) to Fraud, Oswald Labs Platform was able to reduce event tracking latency from 100-150ms to 30-70ms.

How it works

  1. When you use read(key), it queries in-memory cache
  2. If found, returns it from the cache (super fast)
  3. Otherwise, return it from the file system
  4. Save it in cache, so future requests are from the cache

💻 Configuration

You can use the following options in the constructor:

const database = new Fraud({
  directory: "./database", // Where files are stored
  extension: "json", // File extension for JSON files
  update: info => { // Function to call when files are updated
      console.log(info);
  },
  softDelete: false, // Set to true to not delete files, just rename and hide them,
  deletePrefix: "__deleted_", // If soft delete is enabled, use this prefix,
  stdTTL: 0, // Standard TTL number of seconds (0 is unlimited)
  checkperiod: 0 // Period in seconds to automatically perform delete check (0 is no check)
});

Methods

You can use the following methods for programatical access:

| Method | Description | | - | - | | create(fileName, object, overwrite?) | Creates a new file | | delete(fileName) | Deletes a file | | read(fileName) | Reads a file | | readAll() | Reads all files (3.0.0+) | | update(fileName, object) | Patches a file | | list() | Lists all available files | | exists(fileName) (note) | Returns whether file exists | | listCache() | Lists all available cached files (5.0.0+) |

There are also sync versions of each function above (e.g., createSync()).

Note: It is better to use read() and catch a promise rejection than using exists(), because exists skips the cache and only checks the file system to make sure it's available. You should also be careful when using readAll() and list() for the same reason.

For example, you can create a new file like this:

database.create("ara", {
    name: "Ara Isaacson",
    email: "[email protected]",
    phone: {
        countryCode: 31,
        number: "XXXXXXXXX"
    }
});

Then, updating a value is as simple as:

database.update("ara", {
    phone: {
        countryCode: 1
    }
});

Which can be read like this:

database.read("ara").then(user => console.log(user.phone));
// { countryCode: 1, number: "XXXXXXXXX" }

Or using async/await:

const user = await database.read("ara");
console.log(user.phone);
// { countryCode: 1, number: "XXXXXXXXX" }

🛠️ Development

Start development server with Nodemon:

yarn start

Production

Build a production version:

yarn build

✍️ Todo

  • [x] Make it work
  • [ ] Basic queries
  • [x] Save recent files in memory too (~~Redis?~~ nodecache)

📝 License

MIT

Thanks to @aleximb for suggesting the name!