Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

- Add Express TypeScript Postgres/Prisma support with `--db postgres --orm prisma`.
- Replace the legacy bare `--db` MongoDB shortcut with explicit `--db mongodb`.
- Generate Prisma 7 config, schema, seed script, lazy Prisma client, `/users` routes/controllers, Docker Compose, OpenAPI `/users` paths, and database-aware generated tests.
- Update interactive mode, docs, package metadata, and package smoke coverage for the Postgres/Prisma path.

## 2.4.0 - 2026-06-24

- Add Hono framework support with TypeScript-first generated apps, Docker files, generated tests, and JSON routes for `/`, `/about`, `/contact`, and `/health`.
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ServerGen is an npm CLI for scaffolding Node.js, Express, and Hono API projects
with practical defaults: MVC-style folders, health checks, Docker files,
ready-to-run npm scripts, optional Express views, and optional
Mongoose/MongoDB config.
Mongoose/MongoDB or Postgres/Prisma config.

## 30-Second Quick Start

Expand Down Expand Up @@ -53,8 +53,9 @@ npx servergen@latest my-api
| `--framework node` | Plain Node.js HTTP server with `/`, `/about`, `/contact`, and `/health`, plus MVC folders, Docker files, `.gitignore`, generated `README.md`, and `package.json`. |
| `--framework hono` | TypeScript Hono API app with `src/index.ts`, `tsconfig.json`, `test/app.test.ts`, Docker files, `.gitignore`, generated `README.md`, and `package.json`. |
| `--view ejs`, `pug`, or `hbs` | Adds the selected Express view template and renders it from `/`. |
| `--db` | Adds Mongoose, `config/mongoose.js`, and `MONGODB_URI` in `.env.example` for Express apps. |
| `--openapi` | Adds `docs/openapi.yaml`, a static OpenAPI 3.0 spec for generated Express and Hono routes. |
| `--db mongodb` | Adds Mongoose, `config/mongoose.js`, and `MONGODB_URI` in `.env.example` for Express apps. |
| `--typescript --db postgres --orm prisma` | Adds Prisma 7, a Postgres Docker Compose service, `prisma/schema.prisma`, `prisma.config.ts`, `src/lib/prisma.ts`, `/users` routes/controllers, generated route tests, and `DATABASE_URL` in `.env.example` for Express TypeScript apps. |
| `--openapi` | Adds `docs/openapi.yaml`, a static OpenAPI 3.0 spec for generated Express and Hono routes. Postgres/Prisma apps include `/users` paths. |

Generated apps include `npm start` and `npm run dev`. Express apps also include
`npm test`. TypeScript Express and Hono apps also include `npm run build`.
Expand All @@ -74,7 +75,8 @@ servergen [options] [name]
-n, --name <name> name of the app to create
-f, --framework <type> framework: express | node | hono (default: "express")
-v, --view <type> view engine (express only): ejs | pug | hbs
--db add Mongoose and a MongoDB config (express only)
--db <type> database: mongodb | postgres
--orm <type> ORM for supported databases: prisma
--openapi generate an OpenAPI spec file (express and hono)
--typescript generate a TypeScript app where supported
-p, --port <number> port for the generated app (1-65535) (default: "3000")
Expand All @@ -91,7 +93,8 @@ npx servergen@latest my-api
npx servergen@latest my-api --framework node
npx servergen@latest my-api --framework hono
npx servergen@latest my-api --view ejs
npx servergen@latest my-api --db
npx servergen@latest my-api --db mongodb
npx servergen@latest my-api --typescript --db postgres --orm prisma
npx servergen@latest my-api --openapi
npx servergen@latest my-api --typescript
npx servergen@latest my-api --port 8080
Expand Down
14 changes: 11 additions & 3 deletions bin/servergen.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import path from 'path';
import { createRequire } from 'module';
import { program } from 'commander';
import { getConfig } from '../lib/config.js';
import { normalizeDatabaseOption, normalizeOrmOption } from '../lib/database.js';
import { validateOptions } from '../lib/validator.js';
import { createGenerator } from '../index.js';
import * as fileName from '../lib/fileName.js';
Expand All @@ -34,7 +35,8 @@ program
.option('-n, --name <name>', 'name of the app to create')
.option('-f, --framework <type>', 'framework: express | node | hono', 'express')
.option('-v, --view <type>', 'view engine (express only): ejs | pug | hbs')
.option('--db', 'add Mongoose and a MongoDB config (express only)')
.option('--db <type>', 'database: mongodb | postgres')
.option('--orm <type>', 'ORM for supported databases: prisma')
.option('--openapi', 'generate an OpenAPI spec file (express and hono)')
.option('--typescript', 'generate a TypeScript app where supported')
.option('-p, --port <number>', 'port for the generated app (1-65535)', '3000')
Expand All @@ -48,7 +50,8 @@ Examples:
$ servergen my-api -f node create a Node app
$ servergen my-api -f hono create a Hono app
$ servergen my-api -v ejs Express app with the EJS view engine
$ servergen my-api --db Express app with Mongoose/MongoDB
$ servergen my-api --db mongodb Express app with Mongoose/MongoDB
$ servergen my-api --typescript --db postgres --orm prisma
$ servergen my-api --openapi API app with docs/openapi.yaml
$ servergen my-api --typescript TypeScript where supported
$ servergen my-api -p 8080 use a custom port
Expand Down Expand Up @@ -129,11 +132,15 @@ const main = async () => {

const port = parseInt(resolvedOptions.port, 10) || 3000;
const skipInstall = resolvedOptions.skipInstall || false;
const db = normalizeDatabaseOption(resolvedOptions.db);
const orm = normalizeOrmOption(resolvedOptions.orm);

logger.debug('Parsed configuration', {
appName,
db,
port,
framework: resolvedOptions.framework,
orm,
skipInstall,
typescript: resolvedOptions.typescript,
});
Expand All @@ -142,7 +149,8 @@ const main = async () => {
appName,
framework: resolvedOptions.framework,
view: resolvedOptions.view,
db: resolvedOptions.db,
db,
orm,
openapi: resolvedOptions.openapi,
port,
skipInstall,
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The command-by-command examples use `npx --yes servergen@latest` to follow the c
- [Hono app](./hono.md)
- [Express views with EJS, Pug, or HBS](./views.md)
- [Express app with MongoDB/Mongoose config](./mongodb.md)
- [TypeScript Express app with Postgres and Prisma](./postgres-prisma.md)
- [Custom port and Docker notes](./custom-port-docker.md)

## Shared Notes
Expand All @@ -28,6 +29,7 @@ The command-by-command examples use `npx --yes servergen@latest` to follow the c
- Generated apps require Node.js 20 or newer.
- Generation runs `npm install` unless you pass `--skip-install`.
- When install is not skipped, npm also creates `node_modules/` and `package-lock.json` inside the generated app.
- Express-only options: `--view ejs|pug|hbs` and `--db`.
- Express-only options: `--view ejs|pug|hbs` and `--db mongodb`.
- Postgres/Prisma currently requires `--framework express --typescript --db postgres --orm prisma`.
- Hono accepts `--typescript` and `--openapi`; the Hono preset does not support `--view` or `--db`.
- Generated apps include Docker support files. Express apps also include `.env.example`; Node apps do not.
2 changes: 1 addition & 1 deletion docs/examples/hono.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Hono does not support the Express-only view and database options:

```bash
npx --yes servergen@latest hello-hono --framework hono --view ejs
npx --yes servergen@latest hello-hono --framework hono --db
npx --yes servergen@latest hello-hono --framework hono --db mongodb
```

Each command fails before creating the app directory.
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/mongodb.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Use this when you want an Express app with Mongoose installed and a MongoDB conn
## Command

```bash
npx --yes servergen@latest mongo-api --db
npx --yes servergen@latest mongo-api --db mongodb
```

`--db` is Express-only. ServerGen rejects `--framework node --db`.
`--db mongodb` is Express-only. ServerGen rejects `--framework node --db mongodb`.

## What Gets Generated

Expand Down
80 changes: 80 additions & 0 deletions docs/examples/postgres-prisma.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# TypeScript Express App With Postgres And Prisma

Use this when you want an Express TypeScript API with Prisma 7, a local
Postgres service, a generated `User` model, `/users` routes, tests, Docker
files, and OpenAPI docs.

## Generate

```sh
npx --yes servergen@latest users-api --typescript --db postgres --orm prisma --openapi
```

ServerGen creates `users-api/` in the current directory.

## Generated Files

```text
users-api/
├── docker-compose.yml
├── prisma.config.ts
├── prisma/
│ ├── schema.prisma
│ └── seed.ts
├── src/
│ ├── controllers/usersController.ts
│ ├── lib/prisma.ts
│ ├── routes/index.ts
│ ├── routes/users.ts
│ └── index.ts
├── test/
│ ├── app.test.ts
│ └── users.test.ts
├── .env.example
├── Dockerfile
├── package.json
└── tsconfig.json
```

## Run Locally

```sh
cd users-api
npm install
cp .env.example .env
docker compose up -d
npm run db:migrate
npm test
npm run dev
```

In another terminal:

```sh
curl http://localhost:3000/health
curl http://localhost:3000/users
curl -X POST http://localhost:3000/users \
-H "Content-Type: application/json" \
-d '{"email":"ada@example.com","name":"Ada Lovelace"}'
```

## Prisma Commands

```sh
npm run db:generate
npm run db:migrate
npm run db:seed
npm run db:studio
```

## Notes

Postgres/Prisma currently requires Express TypeScript:

```sh
npx --yes servergen@latest users-api --framework express --typescript --db postgres --orm prisma
```

The generated user-route tests run when `DATABASE_URL` is configured. Without a
database URL, those tests are skipped while the generated app health and root
route tests still run.
34 changes: 29 additions & 5 deletions lib/app_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import path from 'path';
import { spawn } from 'child_process';
import fs from 'fs-extra';
import { isMongoDatabase, isPostgresPrisma } from './database.js';

/**
* AppGenerator class that handles the complete app generation workflow.
Expand All @@ -17,7 +18,8 @@ class AppGenerator {
* @param {string} options.appName - The application name.
* @param {string} options.framework - The framework type ('node', 'express', or 'hono').
* @param {string|null} options.view - The view engine name.
* @param {boolean} options.db - Whether to include database configuration.
* @param {false|'mongodb'|'postgres'|string} options.db - Database preset to include.
* @param {string} options.orm - ORM to use for supported database presets.
* @param {boolean} options.openapi - Whether to generate an OpenAPI spec.
* @param {number} options.port - The port number for the app.
* @param {boolean} options.skipInstall - Whether to skip npm install.
Expand All @@ -34,6 +36,7 @@ class AppGenerator {
this.framework = options.framework || 'express';
this.view = options.view;
this.db = options.db;
this.orm = options.orm;
this.openapi = options.openapi || false;
this.port = options.port || 3000;
this.skipInstall = options.skipInstall || false;
Expand All @@ -57,7 +60,9 @@ class AppGenerator {
async generate() {
this.logger?.debug('Starting app generation', {
appName: this.appName,
db: this.db,
framework: this.framework,
orm: this.orm,
openapi: this.openapi,
port: this.port,
skipInstall: this.skipInstall,
Expand Down Expand Up @@ -110,13 +115,20 @@ class AppGenerator {
{ typescript: this.typescript }
);
} else {
const expressOptions = { typescript: this.typescript };
if (isPostgresPrisma(this.db, this.orm)) {
expressOptions.db = this.db;
}
if (this.orm) {
expressOptions.orm = this.orm;
}
this.fileCreator.createExpressApp(
this.templatesDir,
this.folderDir,
this.appName,
this.view,
this.db,
{ typescript: this.typescript }
isMongoDatabase(this.db),
expressOptions
);
}
}
Expand Down Expand Up @@ -163,13 +175,20 @@ class AppGenerator {
* Sets up database configuration if enabled.
*/
setupDatabase() {
if (this.framework === 'express' && this.db) {
if (this.framework === 'express' && isMongoDatabase(this.db)) {
this.fileCreator.handleConfig(
this.folderDir,
this.config.paths.templates.express,
{ typescript: this.typescript }
);
}
if (this.framework === 'express' && isPostgresPrisma(this.db, this.orm)) {
this.fileCreator.handlePostgresPrisma(
this.folderDir,
this.config.paths.templates.express,
this.appName
);
}
}

/**
Expand All @@ -178,11 +197,14 @@ class AppGenerator {
addSupportFiles() {
const typescript = this.typescript || this.framework === 'hono';
const supportOptions = {
db: Boolean(this.db),
db: this.db || false,
openapi: Boolean(this.openapi),
port: this.port,
typescript,
};
if (this.orm) {
supportOptions.orm = this.orm;
}

this.fileCreator.addGitIgnore(this.folderDir, this.templatesDir);
this.fileCreator.addDockerSupport(this.folderDir, this.templatesDir, supportOptions);
Expand All @@ -195,6 +217,8 @@ class AppGenerator {
this.fileCreator.addOpenApiSpec(this.folderDir, {
appName: this.appName,
framework: this.framework,
db: this.db,
orm: this.orm,
port: this.port,
view: this.view,
});
Expand Down
4 changes: 4 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ export const DEPENDENCY_VERSIONS = {
express: '^5.2.1',
hono: '^4.12.27',
'@hono/node-server': '^2.0.6',
'@prisma/adapter-pg': '^7.8.0',
'@prisma/client': '^7.8.0',
mongoose: '^9.7.0',
dotenv: '^17.4.2',
pg: '^8.22.0',
prisma: '^7.8.0',
supertest: '^7.2.2',
typescript: '^5.9.3',
tsx: '^4.21.0',
Expand Down
Loading
Loading