Registry / database / odata-resource

odata-resource

JSON →
library2.0.0jsnpmunverified

odata-resource is a Node.js module (v2.0.0, released 2018-06-03) for building REST APIs with Express, Mongoose, and OData query support. It provides a Resource class that wraps a Mongoose model and automatically generates CRUD routes with OData-like query parameters ($filter, $orderby, $select, $expand, $top, $skip). Key differentiators: minimal boilerplate, support for static and instance-based relationships, custom operators (in, notin), and high customizability. Development appears stable but low activity; last release over 6 years ago. Not recommended for new projects; consider alternatives like odata-v4 or feathers-odata for modern OData support.

npm install odata-resource
INSTALL
IMPORT
SIG · ODATA-RESOURCE
O
odata-resource
databasejavascriptv2.0.0
harness data pending
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.

Resource
var Resource = require('odata-resource'); // or in TypeScript/Esm: import Resource from 'odata-resource';
const Resource = require('odata-resource').Resource;
Module exports the Resource class directly; no named export. Use default import pattern.
Bridge
var Bridge = require('odata-resource/bridge'); // if available
const Bridge = require('odata-resource').Bridge;
Bridge module is at a separate path; not part of main export.
ODataQuery
var ODataQuery = require('odata-resource/odata-query'); // if available
const ODataQuery = require('odata-resource').ODataQuery;
Internal submodules may exist at specific paths; check documentation.

Basic setup with Express, Mongoose model, and Resource initialization. Shows how to define a model and expose CRUD routes with OData query support.

var express = require('express'); var mongoose = require('mongoose'); var Resource = require('odata-resource'); var bodyParser = require('body-parser'); mongoose.connect('mongodb://localhost/test'); var bookModel = mongoose.model('Book', { title: String, genre: String, pages: Number }); var app = express(); app.use(bodyParser.json()); var bookResource = new Resource({ rel: '/api/books', model: bookModel }); bookResource.initRouter(app); app.listen(3000, function() { console.log('REST API running on port 3000'); }); // Test: curl http://localhost:3000/api/books?$filter=pages gt 200
Debug
Known issues
gotchaString filtering is case-sensitive by default due to performance; no support for case-insensitive filtering without additional configuration.
fix
Store a lower-case copy of the property if case-insensitive filtering is needed.
affects: >=1.0.0
deprecatedPackage has not been updated in over 6 years; may contain security vulnerabilities in dependencies.
fix
Use alternative packages like odata-v4 or feathers-odata for current OData support.
affects: >=1.0.0
gotchaThe $filter implementation does not support mixing 'and' and 'or' within a single parenthesized sub-expression.
fix
Rewrite filter to avoid mixing logical operators in the same parentheses, e.g., use nested groups or separate conditions.
affects: >=1.0.0
gotchaNon-OData operators 'in' and 'notin' are available but may not be supported by clients expecting standard OData.
fix
Document API extensions for consumers or use standard OData alternatives like 'any' for collections.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'odata-resource'
Package not installed or installed in wrong location.
fix
Run 'npm install odata-resource' in the project directory.
Resource is not a constructor
Importing the module incorrectly, possibly as a named export instead of default.
fix
Use 'var Resource = require('odata-resource');' without .Resource property.
Cannot read property 'initRouter' of undefined
Resource instance not created properly or options object missing required fields (rel or model).
fix
Ensure new Resource({ rel: '/path', model: mongooseModel }) is called with correct arguments.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
expressrequiredUsed as the HTTP server framework for defining routes.
mongooserequiredRequired for model definition and database operations.
body-parseroptionalRequired for parsing JSON request bodies in POST/PUT operations.
Agent activity
12 hits · last 30 days
node
10
Resources
odata-resource — npm install odata-resource · libregistry