Registry / database / rest-on-mongo

rest-on-mongo

JSON →
library2.4.0jsnpmunverified

rest-on-mongo (v2.4.0) is a Node.js package that provides a REST API layer over MongoDB, enabling direct CRUD operations via HTTP. It supports single or multiple databases with environment-based configuration, authentication via AUTH_TOKEN, read-only modes, and BSON data types. It offers a built-in Express server or library usage. Compared to alternatives, it supports bulk updates and multiple databases, but is REST-ish rather than pure REST. Release cadence is sporadic, with v2.0 introducing breaking changes in BSON handling.

npm install rest-on-mongo
INSTALL
IMPORT
SIG · REST-ON-MONGO
R
rest-on-mongo
databasejavascriptv2.4.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.

default
import restOnMongo from 'rest-on-mongo'
const restOnMongo = require('rest-on-mongo')
Package provides a default export; named exports are available for advanced usage.
Server
import { Server } from 'rest-on-mongo'
const { Server } = require('rest-on-mongo')
Named export for creating custom server; available since v2.0.
Router
import { Router } from 'rest-on-mongo'
Named export for building custom routes; requires Express Router.

Shows two usage modes: quick standalone server via npx and library mode with custom Express server.

import restOnMongo from 'rest-on-mongo'; import express from 'express'; const app = express(); // Use the built-in server (EASY mode) // Just start the server by running 'npx rest-on-mongo' after setting ENV vars // Alternative: Use as library const router = restOnMongo.Router({ db: 'test', server: process.env.MONGO_URI ?? 'mongodb://localhost:27017' }); app.use('/api/v1', router); app.listen(8000, () => console.log('Server running on port 8000')); // Now you can: curl -X POST -H 'Content-Type: application/json' -d '{"name":"test"}' http://localhost:8000/api/v1/mycollection
Debug
Known issues
breakingv2.0 removed automatic conversion of date-like strings to Date objects. Strings starting with $ are no longer converted to special types.
fix
Manually convert strings to Date objects before sending. Use ISO 8601 strings.
affects: >=2.0
deprecatedThe 'autoparse' option for automatic BSON conversion is deprecated.
fix
Use explicit BSON serialization/deserialization in your application code.
affects: >=2.0
gotchaThe server uses a flat route structure by default; if using multiple databases, ensure PREFIXES env variable is set correctly.
fix
Set PREFIXES, SERVER_<prefix>, DB_<prefix> env variables for multi-database mode.
affects: *
gotchaNo CSRF protection or built-in authentication other than a simple token in AUTH_TOKEN header.
fix
Add rate limiting, HTTPS, and proper authentication middleware when exposing publicly.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'rest-on-mongo'
Missing dependency or wrong import path.
fix
Run npm install rest-on-mongo and ensure import path is correct.
MongoDB connection error: MongoNetworkError: failed to connect to server
MongoDB URI is invalid or server is not running.
fix
Check SERVER env variable or mongo URI; ensure MongoDB is accessible.
TypeError: Cannot read property 'Router' of undefined
Using CommonJS require with named export incorrectly.
fix
Use import { Router } from 'rest-on-mongo' or const Router = require('rest-on-mongo').Router.
Upgrade
Version history
2.4.0latest on npm
Audit
Dependencies
expressrequiredWeb framework for built-in server
mongodbrequiredMongoDB driver for database operations
Agent activity
13 hits · last 30 days
node
12
Amazon
1
Resources
rest-on-mongo — npm install rest-on-mongo · libregistry