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

mbfi

v1.1.1

Published

`express-runner` is a utility package that streamlines the process of setting up an Express server with MongoDB and Mongoose, along with essential features like routing, validation, and logging. It simplifies common tasks, allowing you to focus more on bu

Downloads

35

Readme

mbfi Package

mbfi is a utility package that streamlines the process of setting up an Express server with MongoDB and Mongoose, along with essential features like routing, validation, and logging. It simplifies common tasks, allowing you to focus more on building your application and less on boilerplate code. This package includes support for MongoDB connection, schema validation, logging via morgan, CORS handling, and basic routing.

Features

  • Express Server Setup: Simplifies the process of setting up an Express server.
  • MongoDB and Mongoose Integration: Easily connect to MongoDB using Mongoose and handle database operations.
  • Schema Validation: Use simple validation to define your Mongoose schemas.
  • CORS Support: Handles Cross-Origin Resource Sharing (CORS) to allow resources to be shared across different domains.
  • Logging with Morgan: Set up logging to track requests and monitor your server's activity.
  • Router Handling: Easily manage routes with multiple routers for your application.
  • Reusable Components: Helps reduce time in setting up basic server configurations, Mongoose models, and middleware.

Installation

Install the package via npm:

npm install mbfi

How to Use

Basic Setup

To get started with mbfi, you can follow these simple steps to set up a server and connect it to MongoDB.

  1. Create a Server (server.js)
const { run, connectDB, validation, express, router1 } = require('mbfi');

const app = run(5000); // Start the server on port 5000

// Connect to MongoDB
connectDB("mongodb://localhost:27017/mydatabase");

// Define a schema and collection using validation
const userSchema = {
  name: { type: String, required: true },
  email: { type: String, required: true, unique: true },
};

const User = validation("User", userSchema); // Create a Mongoose model with validation

// Use router1 for API routes
app.use("/api", router1);

// Example of defining custom routes
app.get("/", (req, res) => {
  res.send("Hello from CommonJS!");
});

Creating Routes

You can define multiple routers using the built-in express.Router() functionality.

  1. Router Setup (main.js)
const { router1 } = require('mbfi');

router1.get("/", (req, res) => {
  res.send("Welcome to Router 1");
});

module.exports = router1;
  1. Custom Routes in Your App

You can add custom routes to your server with the run function, allowing you to define any additional routes you need for your application.

app.get("/custom", (req, res) => {
  res.send("This is a custom route");
});

MongoDB and Mongoose Integration

The mbfi package integrates MongoDB using Mongoose seamlessly.

  • Connecting to MongoDB: Simply pass your MongoDB connection string to connectDB to establish a connection.
connectDB("mongodb://localhost:27017/mydatabase");
  • Defining a Schema: You can use the validation function to create Mongoose models with validation.
const userSchema = {
  name: { type: String, required: true },
  email: { type: String, required: true, unique: true },
};
const User = validation("User", userSchema);

Logging with Morgan

mbfi includes morgan for logging HTTP requests. This middleware is automatically added to your app when you use the run function.

app.use(morgan("dev")); // Logs all incoming requests

CORS Support

To handle CORS, mbfi includes CORS middleware by default, which allows you to easily share resources across different domains.

app.use(cors()); // Enable CORS

Advanced Configuration (Optional)

You can customize certain features such as logging, database connection settings, and more by modifying the run, connectDB, and validation functions.

Running the Server

To start the Express server, you simply call run and pass the port number as an argument.

const app = run(5000); // Starts the server on port 5000

Use Case

This package is designed to handle all the basic setup for Express and MongoDB, reducing development time for new applications. You can use it for:

  • Rapid Prototyping: Set up your app quickly without worrying about boilerplate code.
  • REST API Development: Handle basic RESTful routing, Mongoose models, and MongoDB operations.
  • MERN Stack Setup: Use this package to build backends for React-based applications.
  • Scalable Applications: Easily extendable to build large applications with multiple routes and complex MongoDB schemas.

Example Project

  1. Create a new project
mkdir my-project
cd my-project
npm init -y
npm install mbfi
  1. Create server.js
const { run, connectDB, validation, express, router1 } = require('mbfi');

const app = run(5000); // Start the server on port 5000

connectDB("mongodb://localhost:27017/mydatabase");

const userSchema = {
  name: { type: String, required: true },
  email: { type: String, required: true, unique: true },
};

const User = validation("User", userSchema);

app.use("/api", router1);

app.get("/", (req, res) => {
  res.send("Hello from CommonJS!");
});
  1. Create main.js
const { router1 } = require('mbfi');

router1.get("/", (req, res) => {
  res.send("Welcome to Router 1");
});

module.exports = router1;
  1. Run the Server
node server.js

Your server will be running at http://localhost:5000, with all the configurations handled for you!


Conclusion

The mbfi package significantly reduces the time needed to set up and configure MongoDB, Mongoose, and Express. With built-in features like validation, logging, and CORS support, it's an ideal starting point for developing applications quickly and efficiently.#