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 🙏

© 2026 – Pkg Stats / Ryan Hefner

json-fs-query

v1.1.0

Published

Use json files to manage and read data.

Readme

json-fs-query

Read and manage data with JSON files - a small query engine that treats a folder of JSON files as a database, with a SQL-like query string (read workouts where date = '2024-06-02') instead of a query builder API.

The core engine (schema management, a full read/insert/update/delete query language, single- and multi-field key support, and referential integrity) is implemented and tested. Still open, tracked for whenever they're actually needed: multi-field foreign keys specifically (single-field ones work; composite primary/unique/index keys work too), and CASCADE/SET NULL modes for referential integrity (deleting/updating a referenced record is RESTRICTed - blocked outright - rather than cascading or nulling out the dependents; see configure() below to turn that enforcement off entirely if it doesn't fit your workflow).

Install

npm install json-fs-query

Usage

const { create, query, drop } = require('json-fs-query')

await create('workouts', [
  { name: '_id', type: 'string', optional: false, autoGenerate: true },
  { name: 'reps', type: 'int', optional: false },
  { name: 'date', type: 'string', optional: false }
], [
  { type: 'primary', fields: ['_id'], lookup: 'pk__id.json' }
])

await query("insert workouts values reps = 10, date = '2024-06-02'")
const rows = await query("read workouts where date = '2024-06-02'")
await query("update workouts set reps = 12 where date = '2024-06-02'")
await query("delete workouts where date = '2024-06-02'")

await drop('workouts')

Configuration

configure() sets where this package's data lives and how strictly it enforces foreign keys - call it once, before anything else:

const { configure } = require('json-fs-query')

configure({
  databasePath: 'database/',   // where the JSON files live (default 'database/')
  relativePath: '',            // URL prefix prepended to databasePath when reading via fetch() in a browser
  enforceForeignKeys: true     // RESTRICT delete/update of a record other entities still reference (default true)
})

Turning enforceForeignKeys off restores the pre-1.0 behavior (no referential integrity checks at all) - useful if it doesn't fit a particular workflow, mirroring MySQL's own toggleable foreign_key_checks.

In the browser

A pre-built bundle is included (browser/jsonFsQuery.js, .min.js - also served directly via unpkg or jsDelivr) and exposes the same functions as a global:

<script src="https://unpkg.com/json-fs-query"></script>
<script>
  jsonFsQuery.configure({ databasePath: 'database/', relativePath: 'https://example.com/' })
  jsonFsQuery.query("read workouts where date = '2024-06-02'").then(console.log)
</script>

Reads work in the browser via fetch() - create/drop, and any write through query() (insert/update/ delete), need real filesystem access and only work in Node. They're still present in the browser build (same public API either way), but throw if actually called there, rather than being silently unavailable.

Documentation

The reference for every function is in docs/ (or open docs/index.html locally). It is generated from the TypeScript source, and each module is a folder of src/data/:

| Module | What it holds | | --- | --- | | introspect | Create, drop and describe a JSON-file "table" (and the policies that validate one) | | queries | Parse a query string and run it - reads, inserts, updates, deletes, joins, where, sortBy, groupBy | | utilities | Shared helpers the queries use - retrieving records/files/indexes and merging join results |

src/index.ts is the package's public entry point - it re-exports query, create, drop, describe, and the schema-definition types (fieldProperties, keyProperties, etc.) needed to build a create() call. Everything else under src/data/ is an internal module, reachable but not part of the supported public API.

Development

npm install
npm test          # the tests
npm run typecheck # the types
npm run build     # dist/ and docs/
npm run docs      # only the documentation