Mongo-express-middleware

Jerry M.
2 min readFeb 8, 2023

I am super excited to share my latest open-source project with all of you — Mongo Express Middleware library! 💻

It all started with a fun weekend project where I was building APIs for a MongoDB database. I usually use Mongoose and mongoose-express-middleware, but I wanted to try something different and work with MongoDB directly this time.

That’s when I realized I needed a library to handle the API layer, so I had to make a choice — find one or build one myself. And you know what I chose! 💪

I put my weekend project on hold and spent my weekends creating a user-friendly express middleware for MongoDB. The goal was to make it as simple and accessible as possible. And I’m pretty happy with the outcome! The library is easy to understand, well-organized, and well-documented.

So, if you want to build APIs for your MongoDB database using Express, this library is for you! Give it a try, and let me know what you think. 🚀

Sample app

const { MongoClient } = require("mongodb");
const express = require('express');
const app = express();

const MongoExpressMiddleware = require('mongo-express-middleware');

const uri = "mongodb://localhost:27017";

const client = new MongoClient(uri);
const database = client.db('test');
const testCollection = database.collection('users');

const crud = new MongoExpressMiddleware(testCollection, null);

console.log(new Date());

app.use(express.json());

app.get('/', crud.find);
app.get('/:id', crud.findById);
app.get('/utils/count', crud.count);
app.post('/', crud.create);
app.put('/:id', crud.update);
app.delete('/', crud.deleteMany);
app.delete('/:id', crud.deleteById);


app.listen(3000, () => {
console.log('Example app listening on port 3000!');
});

--

--

Jerry M.

Manages technology @ appveen. Technology enthusiast. Admirer of algorithms. Husband, dad and beer lover. Views are my own or could have been coerced by my wife.