Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

express-mongo-router

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-mongo-router

RESTful Express router for MongoDB collections

latest
Source
npmnpm
Version
0.2.1
Version published
Maintainers
1
Created
Source

express-mongo-router

This is a small library that offers easy access to MongoDB collection via REST endpoint by offering an Express router.

Example

This example starts an express server on port 3000 with a fruits resource.

const express = require('express');
const MongoClient = require('mongodb');
const Router = require('.').Router;

const MongoURI = 'mongodb://localhost:27017/example';
const server = express();
const port = 3000;

const Collection = name => {
  return MongoClient.connect(MongoURI)
    .then(database => {
      return database.collection(name);
    });
}

const name = 'fruits';
Collection(name).then(collection => {

  const router = Router(name, collection);
  server.use(router);

  console.log(`Express server listening on port ${port}`);
  server.listen(port);
});

FAQs

Package last updated on 17 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts