npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

express-mongowrapper-api

v1.0.0

Published

Express.js API framework using mongoclienteasywrapper for MongoDB operations. Build REST APIs with CRUD operations, file uploads, and advanced features.

Readme

Express Mongowrapper API

Express.js API framework powered by mongoclienteasywrapper for MongoDB operations

npm version npm downloads License: MIT Uses mongoclienteasywrapper

Build REST APIs with Express.js and MongoDB quickly and easily. This framework provides ready-to-use CRUD operations, file upload handling, collection assignments, and more.


🚀 Features

  • Automatic CRUD operations for MongoDB collections
  • File upload support with Multer (images, documents, etc.)
  • Assignment/unassignment handling between collections
  • Recursive delete support for related documents
  • Middleware support for custom processing
  • Async/await based - modern JavaScript, no callback hell
  • Built-in error handling
  • Powered by mongoclienteasywrapper for easy MongoDB operations

📦 Installation

npm install express-mongowrapper-api mongoclienteasywrapper express

🔧 Quick Start

Basic Setup

const express = require("express");
const { create, read, update, remove } = require("express-mongowrapper-api");

const app = express();
app.use(express.json());

// Middleware to attach database connection to request
app.use((req, res, next) => {
  req.database = "mydb"; // Your database name
  next();
});

// Create endpoint
app.post(
  "/api/users",
  create({
    Collection: "users",
  })
);

// Read endpoint
app.get(
  "/api/users",
  read({
    Collection: "users",
  })
);

// Update endpoint
app.put(
  "/api/users/:_id",
  update({
    Collection: "users",
  })
);

// Delete endpoint
app.delete(
  "/api/users/:_id",
  remove({
    Collection: "users",
  })
);

app.listen(3000, () => {
  console.log("Server running on port 3000");
});

📚 API Documentation

create(params)

Creates a new document in the MongoDB collection.

Parameters:

| Parameter | Type | Required | Description | | -------------------- | -------- | -------- | -------------------------------------------------------- | | Database | string | No | Database name (uses req.database if not provided) | | Collection | string | No | Collection name (auto-detected from URL if not provided) | | PathBaseFile | string | No | Base path for file uploads | | URL | string | No | Base URL for file access | | AsyncFunctionAfter | function | No | Async function to execute after creation | | Middleware | boolean | No | If true, passes response to next middleware |

Example:

app.post(
  "/api/products",
  create({
    Database: "shop",
    Collection: "products",
    PathBaseFile: "./uploads",
    URL: "http://localhost:3000/files",
    AsyncFunctionAfter: async (req, res, data) => {
      console.log("Product created:", data.insertedId);
      // Send notification, update cache, etc.
    },
  })
);

Request Body:

{
  "name": "Product Name",
  "price": 29.99,
  "description": "Product description",
  "_Assign": [
    {
      "categories": ["category_id_here"]
    }
  ]
}

Response:

{
  "status": "ok",
  "message": "completed",
  "data": {
    "_id": "generated_id",
    "name": "Product Name",
    "price": 29.99,
    "description": "Product description",
    "datetime": "2025-09-26T10:30:00.000Z"
  }
}

read(params)

Reads documents from the MongoDB collection.

Parameters:

Similar to create().

Example:

app.get(
  "/api/users",
  read({
    Collection: "users",
  })
);

// With query parameters
app.get(
  "/api/users/:_id",
  read({
    Collection: "users",
  })
);

update(params)

Updates an existing document in the MongoDB collection.

Parameters:

Similar to create().

Example:

app.put(
  "/api/products/:_id",
  update({
    Collection: "products",
    AsyncFunctionAfter: async (req, res, data) => {
      console.log("Product updated");
    },
  })
);

Request Body:

{
  "name": "Updated Product Name",
  "price": 39.99
}

remove(params)

Soft deletes a document (marks as deleted).

Parameters:

| Parameter | Type | Required | Description | | ------------ | ------- | -------- | ------------------------------------------- | | Database | string | No | Database name | | Collection | string | No | Collection name | | Middleware | boolean | No | If true, passes response to next middleware |

Example:

app.delete(
  "/api/users/:_id",
  remove({
    Collection: "users",
  })
);

Request Body (optional):

{
  "_Unassign": ["related_collection"],
  "_RecursiveDelete": ["child_collection"]
}

🔥 Advanced Features

File Uploads

const multer = require("multer");
const upload = multer({ dest: "temp/" });

app.post(
  "/api/products",
  upload.single("file"),
  create({
    Collection: "products",
    PathBaseFile: "./uploads",
    URL: "http://localhost:3000/files",
  })
);

The file will be automatically moved to: ./uploads/{database}/{collection}/{document_id}/{filename}

And the document will include:

{
  "foto": "http://localhost:3000/files/mydb/products/123/image.jpg",
  "fotopath": "./uploads/mydb/products/123/image.jpg"
}

Collection Assignments

When creating a document, you can automatically assign it to other collections:

// Creating a user and assigning to groups
{
  "name": "John Doe",
  "email": "[email protected]",
  "_Assign": [
    {
      "groups": ["group_id_1", "group_id_2"]
    }
  ]
}

Recursive Delete

When deleting a document, you can mark related documents as deleted:

// Delete a user and mark all their posts as deleted
app.delete('/api/users/:_id', remove({
  Collection: 'users'
}));

// Request body:
{
  "_RecursiveDelete": ["posts", "comments"]
}

🛠️ Complete Example

Check out the examples folder for complete working examples.


🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 Changelog

See CHANGELOG.md for details about changes in each version.


📄 License

MIT © [Your Name]


🙏 Credits

This project is an improved and maintained version, originally forked from apibuildingframeworkexpress.

Built with:


📞 Support


Made with ❤️ by developers, for developers