nhb-express
Version:
Minimal Express + TypeScript scaffolder with modular structure and flexible stack choices.
147 lines (119 loc) β’ 6.66 kB
Markdown
# π Express TypeScript Drizzle (PostgreSQL) Server
Bootstrapped with [**nhb-express**](https://www.npmjs.com/package/nhb-express)
---
## π¦ 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
- β
**Drizzle** for PostgreSQL integration
- β
**Stylog** from [`nhb-toolbox`](https://toolbox.nazmul-nhb.dev/docs/utilities/misc/stylog) for colorful logging
- β
**[nhb-scripts](https://www.npmjs.com/package/nhb-scripts)** for easy build, commit, module scaffolding, formatting, linting, and more. [see below](#οΈ-scripts)
- β
**Scaffolding via CLI** β choose package manager, DB, etc.
- β
Preβset configs for ESLint, Prettier, and `nhb-scripts`
---
## π Development
Install dependencies (already done by `nhb-express` scaffold)
Run in development mode:
```bash
pnpm dev # or npm run dev / yarn dev
# Runs on port: 4242 by default
```
---
## π Structure
```ini
π <your-project-name>/
ββ π .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 # This file
ββ βοΈ tsconfig.json # Ready to use tsconfig
ββ βοΈ vercel.json # Deployment config for Vercel
```
---
## π οΈ Scripts
- `pnpm/npm/yarn run dev` β Start in dev mode with `nodemon` and `ts-node`
- `pnpm/npm/yarn run start` β Run the built server
- `pnpm/npm/yarn run deploy` β Build the project and deploy to Vercel (`nhb-build && vercel --prod`)
- `pnpm/npm/yarn run build` β Build the project for production (`nhb-build`)
- `pnpm/npm/yarn run build:gen` - Run `drizzle-kit generate` and build the project
- `pnpm/npm/yarn run gen` - Run `drizzle-kit generate` with other arguments
- `pnpm/npm/yarn run migrate` - Run `drizzle-kit migrate` with other arguments
- `pnpm/npm/yarn run drop` - Run `drizzle-kit drop` with other arguments
- `pnpm/npm/yarn run push` - Run `drizzle-kit push` with other arguments
- `pnpm/npm/yarn run pull` - Run `drizzle-kit pull` with other arguments
- `pnpm/npm/yarn run export` - Run `drizzle-kit export` with other arguments
- `pnpm/npm/yarn run check` - Run `drizzle-kit check` with other arguments
- `pnpm/npm/yarn run drizzle:up` - Run `drizzle-kit up` with other arguments
- `pnpm/npm/yarn run studio` - Run `drizzle-kit studio` to open Drizzle Studio in Browser
- `pnpm/npm/yarn run schema` - Create a drizzle schema from template using `nhb-module`
- `pnpm/npm/yarn run module` - Scaffold new module (service, controller, routes, schema etc.) from template using `nhb-module`
- `pnpm/npm/yarn run format` β Format the codebase
- `pnpm/npm/yarn run lint` β Lint the code
- `pnpm/npm/yarn run fix` β Autoβfix lint issues
- `pnpm/npm/yarn run commit` β Guided commit workflow (`nhb-commit`)
- `pnpm/npm/yarn run count` β Count exports (`nhb-count`)
- `pnpm/npm/yarn run delete` β Delete any file/folder from the CLI (`nhb-delete`)
- `pnpm/npm/yarn run secret` β Generate secrets for jwt (using crypto module)
- `pnpm/npm/yarn run typecheck` β runs TypeScript type checking
---
## βοΈ 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).
---
Made with β€οΈ by [Nazmul Hassan](https://github.com/nazmul-nhb)
**Powered by `nhb-express`** π