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.
RestApiPlugin
✓ import { RestApiPlugin } from 'json-rest-api';
✗ import RestApiPlugin from 'json-rest-api';
Named export, not default. Always use named import.
RestApiKnexPlugin
✓ import { RestApiKnexPlugin } from 'json-rest-api';
Required for database integration with knex.
ExpressPlugin
✓ import { ExpressPlugin } from 'json-rest-api';
✗ import { ExpressPlugin } from 'json-rest-api/express';
All plugins are exported from the main package entry point.
Api
✓ import { Api } from 'hooked-api';
✗ import { Api } from 'json-rest-api';
Api class is from 'hooked-api', not from 'json-rest-api'.
all exports (CJS)
✓ const { RestApiPlugin, RestApiKnexPlugin, ExpressPlugin } = require('json-rest-api');
✗ const jsonRestApi = require('json-rest-api');
Use destructuring to access individual exports.
Sets up a JSON:API server with SQLite, defines an 'authors' resource, and starts Express listener.
import { RestApiPlugin, RestApiKnexPlugin, ExpressPlugin } from 'json-rest-api';
import { Api } from 'hooked-api';
import knexLib from 'knex';
import express from 'express';
const knex = knexLib({
client: 'better-sqlite3',
connection: { filename: ':memory:' }
});
const api = new Api({ name: 'book-catalog-api', logLevel: 'trace' });
await api.use(RestApiPlugin);
await api.use(RestApiKnexPlugin, { knex });
await api.use(ExpressPlugin, { mountPath: '/api' });
await api.addResource('authors', {
schema: {
name: { type: 'string', required: true, max: 100, search: true },
surname: { type: 'string', required: true, max: 100, search: true },
},
});
await api.resources.authors.createKnexTable();
const app = express();
app.use('/api', api.router);
app.listen(3000, () => {
console.log('Express server started on port 3000. API available at http://localhost:3000/api');
});
Errors
Common errors & fixes
Cannot find module 'hooked-api'
Missing peer dependency.
fixRun 'npm install hooked-api'.
TypeError: api.use is not a function
Api not imported from 'hooked-api' or incorrectly constructed.
fixEnsure correct import: 'import { Api } from 'hooked-api';' and create instance with 'new Api(...)'. Error: listen EADDRINUSE :::3000
Port already in use by another process.
fixKill the process using port 3000 or change the port in app.listen.
Uncaught TypeError: knexLib is not a function
Incorrect import of knex for ESM modules.
fixUse 'import knexLib from 'knex';' (default import) instead of 'const { knex } = require('knex');'. Audit
Dependencies
hooked-apirequiredCore framework dependency; json-rest-api is a plugin for hooked-api
knexoptionalRequired for database operations via RestApiKnexPlugin
expressoptionalRequired for Express connector
socket.iooptionalOptional peer dependency for real-time features
joseoptionalOptional peer dependency for JWT authentication