Registry / devops / nd5-mongodb-server

nd5-mongodb-server

JSON →
library1.7.2jsnpmunverified

Dynamic Express server with MongoDB and WebSocket support. Version 1.7.2. Provides a rapid-development framework by auto-loading controllers from a file system path and connecting them to MongoDB collections via a helper function. Includes Socket.IO integration for real-time communication. Written in TypeScript with included type definitions. Compared to alternatives like FeathersJS or Sails, this is a minimal, convention-based approach with fewer abstractions, targeting small to medium projects where quick setup is desired.

npm install nd5-mongodb-server
INSTALL
IMPORT
SIG · ND5-MONGODB-SERVER
N
nd5-mongodb-server
devopsjavascriptv1.7.2
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.

StartServer
import { StartServer } from 'nd5-mongodb-server'
const StartServer = require('nd5-mongodb-server')
ESM default export? Actually named export. CommonJS require works but might miss types.
getColletion
import { getColletion } from 'nd5-mongodb-server/mongo'
import { getColletion } from 'nd5-mongodb-server'
Mistyped function name 'getColletion' (should be 'getCollection'?). Also path must be '/mongo' subpath export.
SocketIO.Server
import { Server as SocketIOServer } from 'socket.io'; import { StartServer } from 'nd5-mongodb-server'
import * as SocketIO from 'socket.io'; const io: SocketIO.Server = ...
Socket.IO v3+ removed namespace exports; use named import or direct from 'socket.io'.

Sets up an Express server with MongoDB connection and WebSocket support, auto-loading controllers from a folder.

import { StartServer } from 'nd5-mongodb-server'; import * as path from 'path'; const dbs = [ { db: { name: 'test', collections: ['cars'] } }, ]; const mongodb = 'mongodb+srv://' + (process.env.MONGO_USER ?? '') + ':' + (process.env.MONGO_PASS ?? '') + '@cluster.mongodb.net/test?retryWrites=true&w=majority'; StartServer({ middleWare: (req: any, res: any, next: any) => next(), socketServer: (io: any) => { io.on('connection', (client: any) => { console.log('Client connected'); client.on('message', (data: any) => io.emit('message', data)); }); }, controllersPath: path.join(__dirname, 'controllers'), mongoDB: { url: mongodb, useNewUrlParser: true, useUnifiedTopology: true, dbs: dbs } });
Debug
Known issues
gotchaFunction name 'getColletion' is misspelled (should be 'getCollection'). Expect typo-induced errors.
fix
Use exact spelling 'getColletion' as exported. Do not correct to 'getCollection'.
affects: >=1.0.0
gotchagetColletion returns an object with 'collection' property, not the collection directly. Typos in property access cause undefined errors.
fix
Use destructuring: const { collection } = getColletion({...});
affects: >=1.0.0
deprecateduseNewUrlParser and useUnifiedTopology are deprecated in newer MongoDB driver versions.
fix
Omit these options in MongoDB driver v5+ or set them explicitly if needed for compatibility.
affects: >=4.0.0
breakingIn Express v5, req/res types changed; middleware signatures may break TypeScript compilation.
fix
Update middleware types to Express v5 signatures: (req: Request, res: Response, next: NextFunction) => void.
affects: >=5.0.0
gotchaSocketServer parameter type is SocketIO.Server which only exists in socket.io v2; v3+ uses 'Server' type from 'socket.io' package.
fix
Use socket.io v2 types or adapt to v3: import { Server } from 'socket.io' and type the parameter as Server.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'collection' of 'getColletion(...)' as it is undefined.
Invalid arguments to getColletion: missing collection name or db name.
fix
Ensure the object passed to getColletion has 'collection' (string) and 'db' (string) properties.
Error: Cannot find module 'nd5-mongodb-server/mongo'. Please verify that the package.json has a valid "main" entry.
Import path is wrong; must use 'nd5-mongodb-server/mongo' not 'nd5-mongodb-server/src/mongo'.
fix
Change import to: import { getColletion } from 'nd5-mongodb-server/mongo';
Type 'SocketIO.Server' is not assignable to type 'Server'.
Socket.IO v3+ does not export SocketIO.Server; instead use 'Server' from 'socket.io'.
fix
Use 'import { Server } from 'socket.io'' and type the socketServer parameter as 'Server'.
Property 'useNewUrlParser' does not exist on type 'MongoClientOptions'.
MongoDB driver v5+ removed useNewUrlParser and useUnifiedTopology options.
fix
Remove those options from the mongoDB config object.
Upgrade
Version history
1.7.2latest on npm
Audit
Dependencies
expressrequiredCore HTTP framework for routing and middleware
mongodbrequiredMongoDB driver for database operations
socket.iorequiredWebSocket library for real-time bidirectional event-based communication
Agent activity
2 hits · last 30 days
node
2
Resources
nd5-mongodb-server — npm install nd5-mongodb-server · libregistry