An open API service indexing awesome lists of open source software.

https://github.com/nazmul-nhb/nhb-express

Create Express+TypeScript Server Boilerplate
https://github.com/nazmul-nhb/nhb-express

boilerplate cli drizzle drizzle-kit drizzle-orm express expressjs mongodb mongoose mongoose-odm nodejs prisma prisma-client prisma-orm starter-template typescript zod

Last synced: about 1 month ago
JSON representation

Create Express+TypeScript Server Boilerplate

Awesome Lists containing this project

README

          

# πŸš€ Scaffold Express + TypeScript Server



Downloads


Latest Version


License

Quickly bootstrap a production‑ready **Express + TypeScript + Zod** server with a single command.

> 3 Built-in templates for `MongoDB + Mongoose`, `PostgreSQL + Prisma` and `PostgreSQL + Drizzle`

## ⚑ Compatibility

Node.js 22+

### βœ… Requirements

- Node.js **22 or newer**
- Stable internet connection
- `npm`, `pnpm`, or `yarn` for installation

---

## ✨ Features

- βœ… **TypeScript** with `ts-node` and `nodemon` for development and pre-configured `tsconfig.json`
- βœ… **Express.js** pre‑configured with custom middlewares
- βœ… **Zod** for schema validation
- βœ… **Mongoose** for `MongoDB` integration
- βœ… **Drizzle** or **Prisma** for `PostgreSQL` integration
- βœ… **Stylog** from [`nhb-toolbox`](https://toolbox.nazmul-nhb.dev/docs/utilities/misc/stylog) for colorful logging
- βœ… **Biome** or **Prettier** + **ESLint** for code formatting and linting (your choice during setup)
- βœ… **[nhb-scripts](https://www.npmjs.com/package/nhb-scripts)** for easy build, commit, module scaffolding, and more
- βœ… **Scaffolding via CLI** – choose package manager, DB, ORM/ODM etc.
- βœ… Built‑in [**CI/CD workflow**](#️-cicd-workflow) for automatic deployment to Vercel

---

## πŸ“¦ Usage

You don’t need to install anything globally. Run directly with your favorite package manager:

```bash
# Using npx
npx nhb-express@latest

# Using pnpm
pnpm dlx nhb-express@latest

# Using yarn
yarn dlx nhb-express@latest
```

Follow the interactive prompts:

- Choose a **project name**
- Select a **database** and **ODM/ORM**. Default is `MongoDB` + `Mongoose`.
- Select between `Biome` or `Prettier`+`ESLint` as your **code formatter** and **linter**. Default is `Biome`.
- Pick your **package manager**

Your new server will be scaffolded in the chosen folder with all dependencies installed.

---

## πŸš€ Quick Start

After running the CLI:

```bash
cd
pnpm dev # or npm run dev / yarn dev
# Runs on port: 4242
```

---

## πŸ“ Project Structure

### Mongoose

```ini
πŸ“ /
β”œβ”€ πŸ“ .github/
β”‚ └─ πŸ“ workflows/
β”‚ └─ βš™οΈ publish.yml # GitHub Actions workflow for CI/CD (vercel deployment)
β”‚
β”œβ”€ πŸ“ .vscode/
β”‚ β”œβ”€ πŸ“„ extensions.json # Recommended Extensions for VS Code
β”‚ └─ πŸ“„ settings.json # VS Code Settings for better formatting
β”‚
β”œβ”€ πŸ“ public/ # Folder contains static files
| └─ πŸ–ΌοΈ favicon.png # Favicon to show in client application(s) if supported, e.g. Browsers
β”‚
β”œβ”€ πŸ“ scripts/ # Helper scripts for development purpose
β”‚
β”œβ”€ πŸ“ src/
β”‚ β”œβ”€ πŸ“ app/ # All source (*.ts) files
β”‚ | β”œβ”€ πŸ“ classes/ # Utility classes e.g. `QueryBuilder`, `ErrorWihStatus`
β”‚ | β”œβ”€ πŸ“ configs/ # App configurations
β”‚ | β”œβ”€ πŸ“ constants/ # Constant values
β”‚ | β”œβ”€ πŸ“ errors/ # Custom error processors/handlers
β”‚ | β”œβ”€ πŸ“ middlewares/ # Custom Express middlewares
β”‚ | β”œβ”€ πŸ“ modules/ # Feature modules (controllers, services, etc.)
β”‚ | β”œβ”€ πŸ“ routes/ # Route definitions
β”‚ | β”œβ”€ πŸ“ types/ # Types for the App
β”‚ | └─ πŸ“ utilities/ # Helper functions
β”‚ |
β”‚ β”œβ”€ πŸ“„ app.ts # Express app setup
β”‚ β”œβ”€ πŸ“„ index.d.ts # Global type declarations
β”‚ └─ πŸ“„ server.ts # Server bootstrap
β”‚
β”œβ”€ πŸ”’ .env # Environment variables
β”œβ”€ 🚫 .gitignore # Ignore files/folders from being pushed/committed
β”œβ”€ 🚫 .prettierignore # Ignore files/folders from being formatted with prettier (used if Prettier is selected as formatter)
β”œβ”€ βš™οΈ .prettierrc.json # Prettier config (used if Prettier is selected as formatter)
β”œβ”€ βš™οΈ biome.json # Biome config (used if Biome is selected as formatter)
β”œβ”€ βš™οΈ eslint.config.mjs # ESLint config (used if Prettier + ESLint is selected: flat config, ready for TS)
β”œβ”€ βš™οΈ nhb.scripts.config.mjs # Config for nhb-scripts
β”œβ”€ βš™οΈ nodemon.json # Nodemon config
β”œβ”€ βš™οΈ package.json # Auto-generated `package.json`
β”œβ”€ πŸ“ƒ README.md # This file
β”œβ”€ βš™οΈ tsconfig.json # Ready to use tsconfig
└─ βš™οΈ vercel.json # Deployment config for Vercel
```

### Prisma

```ini
πŸ“ /
β”œβ”€ πŸ“ .github/
β”‚ └─ πŸ“ workflows/
β”‚ └─ βš™οΈ publish.yml # GitHub Actions workflow for CI/CD (vercel deployment)
β”‚
β”œβ”€ πŸ“ .vscode/
β”‚ β”œβ”€ πŸ“„ extensions.json # Recommended Extensions for VS Code
β”‚ └─ πŸ“„ settings.json # VS Code Settings for better formatting
β”‚
β”œβ”€ πŸ“ prisma/
β”‚ └─ πŸ“„ schema.prisma # Prisma Schema file
β”‚
β”œβ”€ πŸ“ public/ # Folder contains static files
| └─ πŸ–ΌοΈ favicon.png # Favicon to show in client application(s) if supported, e.g. Browsers
β”‚
β”œβ”€ πŸ“ scripts/ # Helper scripts for development purpose
β”‚
β”œβ”€ πŸ“ src/
β”‚ β”œβ”€ πŸ“ app/ # All source (*.ts) files
β”‚ | β”œβ”€ πŸ“ configs/ # App configurations (CORS, Database, ENV etc.)
β”‚ | β”œβ”€ πŸ“ constants/ # Constant values
β”‚ | β”œβ”€ πŸ“ errors/ # Custom error Class/processors/handlers
β”‚ | β”œβ”€ πŸ“ middlewares/ # Custom Express middlewares
β”‚ | β”œβ”€ πŸ“ modules/ # Feature modules (controllers, services, etc.)
β”‚ | β”œβ”€ πŸ“ routes/ # Route definitions
β”‚ | β”œβ”€ πŸ“ types/ # Types for the App
β”‚ | └─ πŸ“ utilities/ # Helper functions
β”‚ |
β”‚ β”œβ”€ πŸ“ prisma/ # Prisma Client generated files
β”‚ |
β”‚ β”œβ”€ πŸ“„ app.ts # Express app setup
β”‚ β”œβ”€ πŸ“„ index.d.ts # Global type declarations
β”‚ └─ πŸ“„ server.ts # Server bootstrap
β”‚
β”œβ”€ πŸ”’ .env # Environment variables
β”œβ”€ 🚫 .gitignore # Ignore files/folders from being pushed/committed
β”œβ”€ 🚫 .prettierignore # Ignore files/folders from being formatted with prettier (used if Prettier is selected as formatter)
β”œβ”€ βš™οΈ .prettierrc.json # Prettier config (used if Prettier is selected as formatter)
β”œβ”€ βš™οΈ biome.json # Biome config (used if Biome is selected as formatter)
β”œβ”€ βš™οΈ eslint.config.mjs # ESLint config (used if Prettier + ESLint is selected: flat config, ready for TS)
β”œβ”€ βš™οΈ nhb.scripts.config.mjs # Config for nhb-scripts
β”œβ”€ βš™οΈ nodemon.json # Nodemon config
β”œβ”€ βš™οΈ prisma.config.ts # Prisma config
β”œβ”€ βš™οΈ package.json # Auto-generated `package.json`
β”œβ”€ πŸ“ƒ README.md # Instructions and information
β”œβ”€ βš™οΈ tsconfig.json # Ready to use tsconfig
└─ βš™οΈ vercel.json # Deployment config for Vercel
```

### Drizzle

```ini
πŸ“ /
β”œβ”€ πŸ“ .github/
β”‚ └─ πŸ“ workflows/
β”‚ └─ βš™οΈ publish.yml # GitHub Actions workflow for CI/CD (vercel deployment)
β”‚
β”œβ”€ πŸ“ .vscode/
β”‚ β”œβ”€ πŸ“„ extensions.json # Recommended Extensions for VS Code
β”‚ └─ πŸ“„ settings.json # VS Code Settings for better formatting
β”‚
β”œβ”€ πŸ“ migrations/ # Migration files (will be) generated by drizzle-kit
β”‚
β”œβ”€ πŸ“ public/ # Folder contains static files
| └─ πŸ–ΌοΈ favicon.png # Favicon to show in client application(s) if supported, e.g. Browsers
β”‚
β”œβ”€ πŸ“ scripts/ # Helper scripts for development purpose
β”‚
β”œβ”€ πŸ“ src/ # All source (*.ts) files
β”‚ β”œβ”€ πŸ“ app/ # Application logic and internal configs
β”‚ | β”œβ”€ πŸ“ configs/ # App configurations (CORS, ENV etc.)
β”‚ | β”œβ”€ πŸ“ constants/ # Constant values
β”‚ | β”œβ”€ πŸ“ errors/ # Custom error Class/processors/handlers
β”‚ | β”œβ”€ πŸ“ middlewares/ # Custom Express middlewares
β”‚ | β”œβ”€ πŸ“ modules/ # Feature modules (controllers, services, etc.)
β”‚ | β”œβ”€ πŸ“ routes/ # Route configuration
β”‚ | β”œβ”€ πŸ“ types/ # Types for the App
β”‚ | └─ πŸ“ utilities/ # Helper functions
β”‚ |
β”‚ β”œβ”€ πŸ“ drizzle/ # Drizzle schema and initialization
β”‚ | β”œβ”€ πŸ“ schema/ # Contains drizzle schemas
β”‚ | └─ πŸ“„ index.ts # Drizzle initialization with all schemas
β”‚ |
β”‚ β”œβ”€ πŸ“„ app.ts # Express app setup
β”‚ β”œβ”€ πŸ“„ index.d.ts # Global type declarations
β”‚ └─ πŸ“„ server.ts # Server bootstrap
β”‚
β”œβ”€ πŸ”’ .env # Environment variables
β”œβ”€ 🚫 .gitignore # Ignore files/folders from being pushed/committed
β”œβ”€ 🚫 .prettierignore # Ignore files/folders from being formatted with prettier (used if Prettier is selected as formatter)
β”œβ”€ βš™οΈ .prettierrc.json # Prettier config (used if Prettier is selected as formatter)
β”œβ”€ βš™οΈ biome.json # Biome config (used if Biome is selected as formatter)
β”œβ”€ βš™οΈ eslint.config.mjs # ESLint config (used if Prettier + ESLint is selected: flat config, ready for TS)
β”œβ”€ βš™οΈ nhb.scripts.config.mjs # Config for nhb-scripts
β”œβ”€ βš™οΈ nodemon.json # Nodemon config
β”œβ”€ βš™οΈ package.json # Auto-generated `package.json`
β”œβ”€ πŸ“ƒ README.md # Instructions and information
β”œβ”€ βš™οΈ tsconfig.json # Ready to use tsconfig
└─ βš™οΈ vercel.json # Deployment config for Vercel
```

---

## βš™οΈ CI/CD Workflow

A ready‑to‑use **GitHub Actions workflow** is included in:

```ini
.github/workflows/publish.yml
```

βœ… **What it does:**

- Runs on push to your main branch
- Builds your project
- Deploys automatically to **Vercel** (configured via `vercel.json`)

βœ… **How to use:**

1. Push your project to a GitHub repository.
2. Add your Vercel tokens/secrets as GitHub repository secrets:
Go to `Settings >> Secrets and variables >> Actions >> Repository secrets` and add these variables:
- `VERCEL_ORG_ID`
- `VERCEL_PROJECT_ID`
- `VERCEL_TOKEN`
3. Every time you push to `main` and _version is updated_, GitHub Actions will trigger and deploy your server to Vercel.

You can customize the workflow to fit your own CI/CD needs (e.g., change branches, add tests, deploy elsewhere).

---

## πŸ› οΈ nhb-scripts

This project comes integrated with **[nhb-scripts](https://www.npmjs.com/package/nhb-scripts)** β€” a cli package also by [Nazmul Hassan](https://github.com/nazmul-nhb):

✨ **What you get:**

- `npm/pnpm/yarn run build` β†’ builds your project
- `npm/pnpm/yarn run commit` β†’ guided commit with semantic messages
- `npm/pnpm/yarn run module` β†’ scaffolds new modules
- `npm/pnpm/yarn run fix` β†’ auto‑fix lint issues with ESLint or Biome
- `npm/pnpm/yarn run format` β†’ formats with Prettier or Biome
- `npm/pnpm/yarn run typecheck` β†’ runs TypeScript type checking
- and _more…_ configurable via `nhb.scripts.config.mjs`

You can explore and extend `nhb-scripts` in your project as needed.

---

## ✨ Author

Made with ❀️ by [Nazmul Hassan](https://github.com/nazmul-nhb)