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 🙏

© 2024 – Pkg Stats / Ryan Hefner

rapid-mongo-expresskit

v1.5.0

Published

Rapid Mongo Express Kit is a ready-to-use boilerplate for building Express.js applications with MongoDB. It includes pre-configured authentication, mail sending, error handling, and other utilities to streamline development and reduce repetitive tasks.

Downloads

408

Readme

Rapid Mongo Express Kit

Rapid Mongo Express Kit is a ready-to-use boilerplate for building Express.js applications with MongoDB. It includes pre-configured authentication, mail sending, error handling, and other utilities to streamline development and reduce repetitive tasks.

Features

  • Authentication using JWT and bcrypt
  • MongoDB integration with Mongoose
  • Mail sending with Nodemailer
  • Error handling middleware
  • Environment configuration with dotenv
  • CORS support
  • Cookie parsing
  • Templating with EJS
  • API documentation with Swagger
  • Data validation with Zod
  • Redis support with ioredis

Installation

To create a new project using this kit:

npx rapid-mongo-expresskit my-new-project
cd my-new-project
npm install
npm dev

Usage

After running the above commands, your Express.js application will be ready to use with the included features.

Project Structure

📦rapid-mongo-expresskit 
 ┣ 📂src
 ┃ ┣ 📂app
 ┃ ┃ ┣ 📜app.ts
 ┃ ┃ ┣ 📜errors.ts
 ┃ ┃ ┣ 📜middleware.ts
 ┃ ┃ ┗ 📜routes.ts
 ┃ ┣ 📂builder
 ┃ ┃ ┗ 📜QueryBuilder.ts
 ┃ ┣ 📂config
 ┃ ┃ ┗ 📜index.ts
 ┃ ┣ 📂db
 ┃ ┃ ┣ 📜dbConnect.ts
 ┃ ┃ ┗ 📜redisConnect.ts
 ┃ ┣ 📂docs
 ┃ ┃ ┗ 📜swagger.yaml
 ┃ ┣ 📂errors
 ┃ ┃ ┣ 📜CustomError.ts
 ┃ ┃ ┣ 📜duplicateErrors.ts
 ┃ ┃ ┣ 📜notFoundError.ts
 ┃ ┃ ┣ 📜validation.mongoose.error.ts
 ┃ ┃ ┗ 📜zodError.ts
 ┃ ┣ 📂interfaces
 ┃ ┃ ┣ 📜error.interface.ts
 ┃ ┃ ┗ 📜index.d.ts
 ┃ ┣ 📂middlewares
 ┃ ┃ ┣ 📜auth.ts
 ┃ ┃ ┗ 📜requestValidator.ts
 ┃ ┣ 📂modules
 ┃ ┃ ┣ 📂auth
 ┃ ┃ ┃ ┣ 📜auth.constant.ts
 ┃ ┃ ┃ ┣ 📜auth.controller.ts
 ┃ ┃ ┃ ┣ 📜auth.interface.ts
 ┃ ┃ ┃ ┣ 📜auth.routes.ts
 ┃ ┃ ┃ ┣ 📜auth.service.ts
 ┃ ┃ ┃ ┣ 📜auth.utils.ts
 ┃ ┃ ┃ ┗ 📜auth.validaton.ts
 ┃ ┃ ┣ 📂Demo
 ┃ ┃ ┃ ┣ 📜demo.controller.ts
 ┃ ┃ ┃ ┣ 📜demo.interface.ts
 ┃ ┃ ┃ ┣ 📜demo.model.ts
 ┃ ┃ ┃ ┣ 📜demo.routes.ts
 ┃ ┃ ┃ ┣ 📜demo.service.ts
 ┃ ┃ ┃ ┗ 📜demo.validation.ts
 ┃ ┃ ┗ 📂user
 ┃ ┃ ┃ ┣ 📜user.constant.ts
 ┃ ┃ ┃ ┣ 📜user.controller.ts
 ┃ ┃ ┃ ┣ 📜user.interface.ts
 ┃ ┃ ┃ ┣ 📜user.model.ts
 ┃ ┃ ┃ ┣ 📜user.routes.ts
 ┃ ┃ ┃ ┣ 📜user.service.ts
 ┃ ┃ ┃ ┗ 📜user.validation.ts
 ┃ ┣ 📂routes
 ┃ ┃ ┗ 📜index.ts
 ┃ ┣ 📂test
 ┃ ┃ ┗ 📜dataTest.ts
 ┃ ┣ 📂utils
 ┃ ┃ ┣ 📜catchAsync.ts
 ┃ ┃ ┣ 📜emailSender.ts
 ┃ ┃ ┣ 📜genarateToken.ts
 ┃ ┃ ┗ 📜sendResponse.ts
 ┃ ┣ 📂views
 ┃ ┃ ┣ 📜email.ejs
 ┃ ┃ ┣ 📜reset.ejs
 ┃ ┃ ┗ 📜success_mail.ejs
 ┃ ┗ 📜index.ts
 ┣ 📜.env
 ┣ 📜.env.example
 ┣ 📜.eslintignore
 ┣ 📜.eslintrc.json
 ┣ 📜.gitignore
 ┣ 📜.prettierrc.json
 ┣ 📜package.json
 ┣ 📜pnpm-lock.yaml
 ┣ 📜readme.md
 ┗ 📜tsconfig.json

Create Module routes controller service using cli

you Can Create full Module with Boilarplate code using cli command :

pnpm create-module <module-name>

now you can see your routes interface model controller and service boilerplate code is available under src/modules/ folder like

module-name.model.ts
module-name.controller.ts
module-name.service.ts
module-name.interface.ts
module-name.validation.ts
module-name.routes.ts

modulename.model.ts


  import { Schema, model } from 'mongoose';
import { IModulename } from './modulename.interface';

const modulenameSchema = new Schema<IModulename>({
  email: {
    type: String,
    required: true,
  },
  name: {
    type: String,
    required: true,
  },
  phone: {
    type: String,
  },
});


  export const Modulename = model<IModulename>('Modulename', modulenameSchema);

modulename.interface.ts


// modulename.model.ts
export interface IModulename {
  name: string;
  email: string;
  phone?: string;

  // update your content here 
}

modulename.validation.ts

// modulename.validation.ts

import { z } from 'zod';
export const modulenameValidationSchema = z.object({
  body: z.object({
    email: z.string(),
    name: z.string(),
    avatar: z.string(),
  }),
});

modulename.controller.ts


// Modulename.controller.ts
  import { RequestHandler } from 'express';
  import {  sendResponse } from '../../utils/sendResponse';
  import { catchAsync } from '../../utils/catchAsync';
  import { createModulenameService } from './modulename.service'; // Update with your service path

  export const getAllModulenameController: RequestHandler = catchAsync(async (req, res) => {
    const result = await createModulenameService(req.body);
    sendResponse(res, {
      status: 201,
      success: true,
      message: 'Successfully created modulename',
      data: result,
    });
  });

modulename.service.ts


// modulename.service.ts

  import { IModulename } from "./modulename.interface";
  import { Modulename } from "./modulename.model";

  export const createModulenameService = async (payload: IModulename) => {
const result = await Modulename.create(payload);
return result;
};

modulename.routes.ts

// modulename.routes.ts

import { Router } from 'express';

export const modulenameRoutes: Router = Router();

modulenameRoutes.post('/demo');

How to Implement Routes

  • go to src/routes
  • open index.ts
  • you can see here :
import { Router } from 'express';
import { userRoutes } from '../modules/user/user.routes';
import { authRoutes } from '../modules/auth/auth.routes';

type IModulerRoutes = { path: string; route: Router }[];

export const modulerRoutes: IModulerRoutes = [
  {
    path: '/user',
    route: userRoutes,
  },
  {
    path: '/auth',
    route: authRoutes,
  },
];

this is built-in routes for authentication if you want to add new routes then format is:

{
    path:'endpoint here'
    route: modulenameRoutes
}

Advance Data Query and Filtering

you can add get Request and sorting querey searching in your service code format is:

    export const getAllModulnameService = async (query: Record<string, unknown>) => {
      const moduleQueries = new QueryBuilder(Modulename.find(), query)
      .fields()
      .filter()
      .sort()
      .search('search value here ')

      const result = await moduleQueries.modelQuery;
      return result ;
};

License

This project is licensed under the MIT License.