UNPKG

nhb-express

Version:

Minimal Express + TypeScript scaffolder with modular structure and flexible stack choices.

142 lines (114 loc) β€’ 6.13 kB
# πŸš€ 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`** πŸš€