nhb-express
Version:
Minimal Express + TypeScript scaffolder with modular structure and flexible stack choices.
142 lines (114 loc) β’ 6.13 kB
Markdown
# π Express TypeScript Prisma (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
- β
**Prisma** 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.
<!-- - β
Builtβin [**CI/CD workflow**](#οΈ-cicd-workflow) for automatic deployment to Vercel -->
- β
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
β
ββ π 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 # 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 `prisma generate` and build the project
- `pnpm/npm/yarn run migrate` - Run `prisma migrate dev` to make new migration
- `pnpm/npm/yarn run reset` - Run `prisma migrate reset` to reset migration
- `pnpm/npm/yarn run studio` - Run `prisma studio` to view/edit data in the browser
- `pnpm/npm/yarn run gen` - Run `prisma generate` to generate Prisma Client
- `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 module` - Scaffold new module (service, controller, routes, schema etc.) from template using `nhb-module`
- `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`** π