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

node-backend-boilerplate-template

v1.0.1

Published

<!-- [![NPM Version](https://img.shields.io/npm/v/your-backend-boilerplate.svg)](https://www.npmjs.com/package/your-backend-boilerplate) [![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) -->

Downloads

2

Readme

🚀 Your Backend Boilerplate Name

A quick and easy way to bootstrap new backend projects with a pre-configured structure for controllers, routes, and services. Get started with your API development in minutes!


✨ Features

  • Standardized Structure: Consistent folder organization for controllers, Service Respositry routes, services, etc.
  • Ready-to-use: Basic app.ts (or index.js) setup for quick starts.
  • Scalable: Designed to be easily expandable for growing projects.
  • Fast Setup: Generate a new project with a single command.

📦 Installation & Usage

To generate a new backend project using this boilerplate, simply run the following command in your terminal:

npx-create-node-backend-boilerplate-template <your-project-name>

Psudo code:

  1. Controller
export class UserController {
  constructor(private userService: UserService) {}

  // Create a new user
  public registerUser = async (
    req: Request,
    res: Response,
    next: NextFunction
  ) => {
    try {
      const { user, token } = await this.userService.registerUser(req.body);
      res.cookie("token", token, cookieOptions);
      sendResponse(
        req,
        res,
        httpStatusCodes.created,
        userResponseMessage.created,
        user,
        { token }
      );
    } catch (error) {
      next(error);
    }
  };

}
  1. Service

export class UserService extends BaseService<IUser> {
  private readonly userRepository: UserRepository;
  constructor(userRepository: UserRepository) {
    super(userRepository);
    this.userRepository = userRepository;
  }

  // Create a new user
  public async registerUser(
    userData: Partial<IUser>
  ): Promise<{ user: IUser; token: string }> {
    const data = { ...userData };
    const existingUser = await this.userRepository.findOne({
      phoneNo: userData.phoneNo,
    });
    if (existingUser) {
      throw new CustomError(
        httpStatusCodes.conflict,
        userResponseMessage.alreadyRegister
      );
    }
    if(userData.rating){
      delete userData.rating
    }
    userData.password = await this.generateHashedPassword(userData.password!);
    await this.createDocument(userData); //as IUser & Document

    const { user, token } = await this.loginUser(data);
    return { user, token };
  }
}
  1. Respository

import { BaseRepository } from "./BaseRepository";
import { IUser, UserModel } from "../models/UserModel";

export class UserRepository extends BaseRepository<IUser> {
  constructor() {
    super(UserModel);  // 🔥 Pass the Mongoose Model to BaseRepository
  }

}
  1. Routes

class UserRoutes {
  router: Router;
  constructor(private userController: UserController) {
    this.router = Router();
    this.initializeRoutes();
  }
  private initializeRoutes() {
    this.router.post(
      "/register",
      ValidationMiddleware(UserDTO.pick({ phoneNo: true, password: true, name: true })),
      this.userController.registerUser
    );
  }
const userRepository = new UserRepository();
const userService = new UserService(userRepository);
const userController = new UserController(userService);
export const userRoutes = new UserRoutes(userController).router;
  1. App
import express from 'express'
import cors from 'cors'
import helmet from 'helmet'
import dotenv from 'dotenv'
import cookieParser from 'cookie-parser'
import Database from './config/Database'
import { globalErrorHandler } from './middlewares/globalErrorHandler'
import path from 'path'
import { userRoutes } from './routes/UserRoutes'

dotenv.config()
class App {
  public app: express.Application
  constructor () {
    // 1. Initialize core Express application first
    this.app = express()
    // 2. Configure middleware (security, parsers, etc.)
    this.config()
    // 3. Establish database connection
    this.connectDatabase()
    // 4. Initialize all route instances (after database connection)
    // this.testRoutes = new testRoutes()
    // 5. Register routes (after middleware and route initialization)
    this.routes()
    // 6. Add error handling (LAST - after all other middleware/routes)
    this.handleErrors()
  }

  private config (): void {
    this.app.use(cookieParser())
    this.app.use(cors())
    this.app.use(helmet())
    this.app.use(express.json())
    // ✅ Set EJS as the templating engine
    this.app.set('view engine', 'ejs')
    // this.app.set('views', path.join(__dirname, 'views'))
    this.app.set('views', path.join(__dirname, '../views'))
    // ✅ Serve static files correctly
    this.app.use('/public', express.static('public'))
  }
  private connectDatabase (): void {
    console.log('Connecting to database...')
    Database.connect()
  }
  

  private routes (): void {
    this.app.use('/api/v1/users', userRoutes)
  }

  private handleErrors (): void {
    this.app.use(globalErrorHandler) // Global error handler should be the last middleware
  }
}

export default new App().app