{"id":15674583,"url":"https://github.com/anandchowdhary/fraud","last_synced_at":"2025-04-16T03:48:43.327Z","repository":{"id":34219980,"uuid":"171870819","full_name":"AnandChowdhary/fraud","owner":"AnandChowdhary","description":"🗄 File-based key-JSON database with nodecache","archived":false,"fork":false,"pushed_at":"2024-06-17T19:25:47.000Z","size":784,"stargazers_count":16,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T19:03:12.927Z","etag":null,"topics":["filesystem","fs","library","nodejs","typescript"],"latest_commit_sha":null,"homepage":"https://anandchowdhary.github.io/fraud/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AnandChowdhary.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-21T12:49:05.000Z","updated_at":"2025-03-02T03:14:02.000Z","dependencies_parsed_at":"2024-10-23T12:09:04.679Z","dependency_job_id":null,"html_url":"https://github.com/AnandChowdhary/fraud","commit_stats":{"total_commits":278,"total_committers":4,"mean_commits":69.5,"dds":0.2230215827338129,"last_synced_commit":"9a0526a9a121c9db75f7f6a71a94ffdf570e742b"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandChowdhary%2Ffraud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandChowdhary%2Ffraud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandChowdhary%2Ffraud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandChowdhary%2Ffraud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AnandChowdhary","download_url":"https://codeload.github.com/AnandChowdhary/fraud/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249192448,"owners_count":21227792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filesystem","fs","library","nodejs","typescript"],"created_at":"2024-10-03T15:47:17.696Z","updated_at":"2025-04-16T03:48:43.309Z","avatar_url":"https://github.com/AnandChowdhary.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🗄 Fraud\n\n[![NPM](https://img.shields.io/npm/v/fraud.svg)](https://www.npmjs.com/package/fraud)\n[![Build](https://img.shields.io/travis/AnandChowdhary/fraud.svg)](https://travis-ci.org/AnandChowdhary/fraud)\n[![Coveralls](https://img.shields.io/coveralls/github/AnandChowdhary/fraud.svg)](https://coveralls.io/github/AnandChowdhary/fraud)\n![Type definitions](https://img.shields.io/npm/types/fraud.svg?color=brightgreen)\n[![GitHub](https://img.shields.io/github/license/anandchowdhary/fraud.svg)](https://github.com/AnandChowdhary/fraud/blob/master/LICENSE)\n![Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/AnandChowdhary/fraud.svg)\n\nFraud 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](https://github.com/mpneuried/nodecache), with added utilities.\n\n## ⭐ How it works\n\nAdd fraud to your project with NPM:\n\n```bash\nnpm install fraud\n```\n\nAdd it to your project:\n\n```js\nconst Fraud = require(\"fraud\");\n```\n\nInitialize it with the directory of your database:\n\n```js\nconst database = new Fraud({\n    directory: \"./database\"\n});\n```\n\nNow, 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).\n\n## 💡 Why Fraud\n\n- No-config database for key-JSON storage\n- Caches everything in memory, uses file system if uncached\n- Super fast and super low-latency\n\n**Real use case:** Switching API configuration from MySQL (managed RDS in the same region as an EC2) to Fraud, [Oswald Labs Platform](https://oswaldlabs.com/platform/) was able to reduce event tracking latency from 100-150ms to 30-70ms.\n\n### How it works\n\n1. When you use `read(key)`, it queries in-memory cache\n2. If found, returns it from the cache (super fast)\n3. Otherwise, return it from the file system\n4. Save it in cache, so future requests are from the cache\n\n## 💻 Configuration\n\nYou can use the following options in the constructor:\n\n```js\nconst database = new Fraud({\n  directory: \"./database\", // Where files are stored\n  extension: \"json\", // File extension for JSON files\n  update: info =\u003e { // Function to call when files are updated\n      console.log(info);\n  },\n  softDelete: false, // Set to true to not delete files, just rename and hide them,\n  deletePrefix: \"__deleted_\", // If soft delete is enabled, use this prefix,\n  stdTTL: 0, // Standard TTL number of seconds (0 is unlimited)\n  checkperiod: 0 // Period in seconds to automatically perform delete check (0 is no check)\n});\n```\n\n### Methods\n\nYou can use the following methods for programatical access:\n\n| Method | Description |\n| - | - |\n| `create(fileName, object, overwrite?)` | Creates a new file |\n| `delete(fileName)` | Deletes a file |\n| `read(fileName)` | Reads a file |\n| `readAll()` | Reads all files (3.0.0+) |\n| `update(fileName, object)` | Patches a file |\n| `list()` | Lists all available files |\n| `exists(fileName)` (note) | Returns whether file exists |\n| `listCache()` | Lists all available cached files (5.0.0+) |\n\nThere are also `sync` versions of each function above (e.g., `createSync()`).\n\n**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.\n\nFor example, you can create a new file like this:\n\n```js\ndatabase.create(\"ara\", {\n    name: \"Ara Isaacson\",\n    email: \"hi@araassistant.com\",\n    phone: {\n        countryCode: 31,\n        number: \"XXXXXXXXX\"\n    }\n});\n```\n\nThen, updating a value is as simple as:\n\n```js\ndatabase.update(\"ara\", {\n    phone: {\n        countryCode: 1\n    }\n});\n```\n\nWhich can be read like this:\n\n```js\ndatabase.read(\"ara\").then(user =\u003e console.log(user.phone));\n// { countryCode: 1, number: \"XXXXXXXXX\" }\n```\n\nOr using async/await:\n\n```js\nconst user = await database.read(\"ara\");\nconsole.log(user.phone);\n// { countryCode: 1, number: \"XXXXXXXXX\" }\n```\n\n## 🛠️ Development\n\nStart development server with Nodemon:\n\n```bash\nyarn start\n```\n\n### Production\n\nBuild a production version:\n\n```bash\nyarn build\n```\n\n## ✍️ Todo\n\n- [x] Make it work\n- [ ] Basic queries\n- [x] Save recent files in memory too (~~Redis?~~ nodecache)\n\n## 📝 License\n\nMIT\n\nThanks to [@aleximb](https://github.com/aleximb) for suggesting the name!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanandchowdhary%2Ffraud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanandchowdhary%2Ffraud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanandchowdhary%2Ffraud/lists"}