Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
API
✓ import { API } from 'arrest'
✗ const API = require('arrest').API
ESM-only since v15; no CommonJS support.
MongoResource
✓ import { MongoResource } from 'arrest'
✗ import { MongoResource } from 'arrest/lib/MongoResource'
Do not import from internal paths; public symbols are exported from the package root.
Resource
✓ import { Resource } from 'arrest'
✗ const Resource = require('arrest').Resource
Use named import; there is no default export for Resource.
Create a minimal CRUD API backed by MongoDB with automatic OpenAPI spec generation.
import { API, MongoResource } from 'arrest';
const api = new API({
title: 'My API',
version: '1.0.0'
});
api.addResource(new MongoResource(process.env.MONGO_URI ?? 'mongodb://localhost:27017/mydb', {
name: 'User',
collection: 'users'
}));
api.listen(3000);
console.log('API running at http://localhost:3000');
console.log('OpenAPI spec at http://localhost:3000/openapi.json');
Debug
Known issues
breakingv15 dropped Node.js <20 support and switched to ESM-only (no CommonJS).fixUpgrade Node.js to >=20 and convert project to ESM (use import, not require).
affects: >=15.0.0
breakingMongoResource now requires MongoDB 7.x. Connection string must reference a MongoDB 7.x server.fixUpgrade MongoDB server to 7.x or stick with arrest v14.
affects: >=15.0.0
breakingbson major version bump to 7.x changed ObjectId behavior. `_id` is now returned as a 24-character hex string by default.fixUse `new bson.ObjectId(id)` to convert hex strings to ObjectIds if needed.
affects: >=15.0.0
gotchaOpenAPI spec endpoint is at /openapi.json by default; ensure no other middleware conflicts.fixConfigure `specPath` option in API constructor to change the path.
affects: >=1.0.0
gotchaResource names must be singular; arrest automatically pluralizes for endpoints. Using a plural name may cause unexpected route generation.fixUse singular names (e.g., 'User' not 'Users').
affects: >=1.0.0
deprecated`api.addResource()` with a plain object (without `name` and `collection`) is deprecated. Always provide a `MongoResource` instance.fixPass a `MongoResource` or custom `Resource` instance.
affects: >=15.0.0 <16.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module /path/to/node_modules/arrest/src/index.js from ... not supported.
arrest v15 is ESM-only; CommonJS require is not supported.
fixUse `import` syntax or switch to dynamic import: `const arrest = await import('arrest')`. MongoError: bad auth Authentication failed.
MongoDB connection string missing credentials or incorrect database permissions.
fixUse `mongodb://user:password@host:port/db?authSource=admin` with correct credentials.
ValidationError: should have required property 'name'
Missing required field in request body as per JSON Schema.
fixCheck the schema defined for the resource; include all required fields in the request.
TypeError: api.addResource is not a function
Importing incorrectly (e.g., `import arrest from 'arrest'` instead of `import { API } from 'arrest'`).
fixUse named imports: `import { API } from 'arrest'` and instantiate `new API()` before calling methods. Audit
Dependencies
No dependency data recorded yet.