{"id":16932,"library":"warehouse","title":"Warehouse JSON Database","description":"Warehouse is a simple JSON-based database library for Node.js, providing a robust interface for managing data through Models, Schemas, and a flexible querying system. It is notably the underlying data store for the Hexo static site generator. The current stable version is 6.0.0, released recently in 2024, indicating active development. The project maintains a consistent release cadence with significant updates, including performance improvements and type refinements in recent major versions. Key differentiators include its focus on a structured schema-driven approach for JSON data, a powerful query engine, and strong TypeScript support, making it suitable for applications requiring local data persistence and structured access without a full-fledged SQL or NoSQL server. It has dropped support for older Node.js versions, currently requiring Node.js 18 or higher.","status":"active","version":"6.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/hexojs/warehouse","tags":["javascript","database","json","db","typescript"],"install":[{"cmd":"npm install warehouse","lang":"bash","label":"npm"},{"cmd":"yarn add warehouse","lang":"bash","label":"yarn"},{"cmd":"pnpm add warehouse","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The `Database` class is the primary export. Instantiation requires the `new` keyword. Since v3.0.0, it is implemented as a class, not a constructor function.","wrong":"import { Database } from 'warehouse'; // Incorrect for default export\nconst { Database } = require('warehouse'); // Incorrect for default export","symbol":"Database","correct":"import Database from 'warehouse'; // ESM\nconst Database = require('warehouse'); // CommonJS"},{"note":"The `SchemaType` base class, used for defining custom schema types, is located in a dedicated submodule. Since v3.0.0, custom SchemaTypes must extend a class declaration.","wrong":"import { SchemaType } from 'warehouse'; // Incorrect import path\nconst SchemaType = require('warehouse'); // Incorrect import path","symbol":"SchemaType","correct":"import SchemaType from 'warehouse/schematype'; // ESM\nconst SchemaType = require('warehouse/schematype'); // CommonJS"},{"note":"For TypeScript, core interfaces like `Model` and `Schema`, as well as the `Database` class type, are typically imported as named types from the main 'warehouse' package.","symbol":"Model, Schema","correct":"import type { Model, Schema, Database } from 'warehouse';"}],"quickstart":{"code":"const Database = require('warehouse');\nconst db = new Database();\n\nconst Post = db.model('posts', {\n  title: String,\n  created: {type: Date, default: Date.now}\n});\n\nPost.insert({\n  title: 'Hello world'\n}).then(function(post){\n  console.log('New post created:', post);\n}).catch(err => {\n  console.error('Error creating post:', err.message);\n});","lang":"javascript","description":"Initializes a Warehouse database, defines a 'Post' model with a schema including a default date, and demonstrates inserting a new post."},"warnings":[{"fix":"Upgrade your Node.js environment to version 18 or higher before upgrading to Warehouse v6.0.0.","message":"Warehouse v6.0.0 dropped support for Node.js 16.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Refactor any direct `Database` instantiations or custom `SchemaType` definitions to use modern JavaScript class syntax (`class MyClass extends Base { ... }`). Refer to the official documentation or release notes for examples.","message":"In Warehouse v3.0.0, the constructor for `Database` and custom `SchemaType` classes changed from a function declaration to a class declaration.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Review your model export logic and replace deprecated `exportAsync()` calls with the new API methods introduced in v4.0.0 as per the documentation.","message":"Warehouse v4.0.0 replaced the `exportAsync()` method.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Always check the `engines` field in `package.json` or the release notes (`BREAKING CHANGES`) before upgrading major versions of 'warehouse' to ensure Node.js compatibility and update your environment accordingly.","message":"Warehouse frequently updates its minimum Node.js version requirement between major releases, potentially breaking CI/CD pipelines or deployments if not monitored.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Upgrade to Warehouse v4.0.2 or higher to resolve the underlying bug related to JSONStream handling.","cause":"An internal issue with JSONStream re-implementation in early 4.x versions could lead to this error when handling large data sets.","error":"RangeError: Invalid string length"},{"fix":"Ensure you are importing `Database` correctly for your module system (`require('warehouse')` or `import Database from 'warehouse'`) and that you are instantiating it with the `new` keyword (e.g., `const db = new Database();`).","cause":"This error typically occurs if you attempt to use `Database` as a function or if the import mechanism (CommonJS vs. ESM) is incorrectly applied, especially after v3.0.0's switch to class declarations.","error":"TypeError: Database is not a constructor"},{"fix":"Upgrade your Node.js environment to meet the minimum version specified in the `engines` field of the `warehouse` package's `package.json` file.","cause":"The installed version of Warehouse requires a newer Node.js runtime than the one currently in use. For example, v6.0.0 requires Node.js 18+.","error":"Error: Node.js version not supported"}],"ecosystem":"npm","meta_description":null}