@alexmc2/create-express-api-starter 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,6 +4,12 @@
4
4
 
5
5
  A beginner-friendly npm CLI that scaffolds Express APIs with best-practice structure and optional educational comments.
6
6
 
7
+ ## About
8
+
9
+ Most Express projects require some initial setup, including folders, middleware, error handling, and testing. This CLI tool automates this process so you can start writing routes immediately. It includes a standard, readable codebase with a pre-configured Jest and Supertest suite that passes right out of the box.
10
+
11
+ The CLI offers multiple configuration options to suit different preferences and use cases, including:
12
+
7
13
  - JavaScript or TypeScript
8
14
  - Simple or MVC architecture
9
15
  - In-memory or PostgreSQL (local `psql` or Docker)
@@ -15,35 +21,18 @@ A beginner-friendly npm CLI that scaffolds Express APIs with best-practice struc
15
21
 
16
22
  <br />
17
23
 
18
- > Works on Linux, macOS, and Windows. The screenshot above shows Linux-specific Postgres setup, but the generated README includes instructions for all platforms.
24
+ > The CLI works on Linux, macOS, and Windows.
19
25
 
20
26
  ## Table of contents
21
27
 
22
- - [@alexmc2/create-express-api-starter](#alexmc2create-express-api-starter)
28
+ - [About](#about)
23
29
  - [Table of contents](#table-of-contents)
24
30
  - [Installation](#installation)
25
- - [npm create (recommended)](#npm-create-recommended)
26
- - [npm init](#npm-init)
27
- - [npx (equivalent)](#npx-equivalent)
28
- - [Global install (optional)](#global-install-optional)
29
31
  - [Usage examples](#usage-examples)
30
- - [Interactive flow](#interactive-flow)
31
- - [Accept defaults (non-interactive)](#accept-defaults-non-interactive)
32
- - [Dry run](#dry-run)
33
- - [Why this exists](#why-this-exists)
34
32
  - [How it works](#how-it-works)
35
33
  - [Options](#options)
36
- - [CLI flags](#cli-flags)
37
34
  - [What gets generated](#what-gets-generated)
38
- - [Project structure (Simple architecture, JavaScript)](#project-structure-simple-architecture-javascript)
39
- - [Middleware](#middleware)
40
- - [Error handling](#error-handling)
41
- - [Scripts](#scripts)
42
- - [Tests](#tests)
43
35
  - [Database modes](#database-modes)
44
- - [In-memory (default)](#in-memory-default)
45
- - [Postgres (psql)](#postgres-psql)
46
- - [Postgres (Docker)](#postgres-docker)
47
36
  - [Educational comments](#educational-comments)
48
37
  - [Design decisions](#design-decisions)
49
38
  - [Requirements](#requirements)
@@ -77,14 +66,12 @@ npx @alexmc2/create-express-api-starter my-api
77
66
  npm install -g @alexmc2/create-express-api-starter
78
67
  ```
79
68
 
80
- > The npm package page may show `npm i @alexmc2/create-express-api-starter`. That command installs the package into your current project. For one-off scaffolding, use `npm create`, `npm init`, or `npx`.
81
-
82
69
  ## Usage examples
83
70
 
84
71
  ### Interactive flow
85
72
 
86
73
  ```bash
87
- npm create @alexmc2/express-api-starter@latest my-api
74
+ npm create @alexmc2/express-api-starter@latest
88
75
  ```
89
76
 
90
77
  ### Accept defaults (non-interactive)
@@ -109,28 +96,19 @@ npm test # Run the test suite
109
96
  npm run lint # Run ESLint
110
97
  ```
111
98
 
112
- Your API is live at `http://localhost:3000`. Hit `http://localhost:3000/health` to confirm.
113
-
114
- ## Why this exists
115
-
116
- Express is unopinionated by design. That's great, but it means every new project starts with the same setup: folder structure, middleware wiring, error handlers, test runner, linting. This tool does all of that for you so you can skip straight to writing routes.
117
-
118
- The generated project is simple enough to understand and modify. It's not a framework - it's a starting point that gets out of your way.
99
+ Your API is live at `http://localhost:3000`. Go to `http://localhost:3000/health` to confirm.
119
100
 
120
101
  ## How it works
121
102
 
122
- This is a two-part system:
103
+ The interactive CLI prompts you for configuration preferences and generates your project files from templates.
123
104
 
124
- 1. **The CLI** (this package) - asks what you want, then generates files from templates.
125
- 2. **The generated project** - a standalone Express API in its own folder with its own dependencies, scripts, and tests. The CLI exits after creating it.
126
-
127
- When you run `npm create @alexmc2/express-api-starter@latest my-api` (or the equivalent `npm init`/`npx` command), npm downloads the CLI, generates the project into `my-api/`, optionally runs `npm install`, and exits. The generated project has no dependency on this tool.
105
+ When you run `npm create @alexmc2/express-api-starter@latest my-api`, npm downloads the CLI to build the project directly in your folder. You are left with a standalone Express API with its own scripts and tests, and the generated project has no ongoing dependency on this tool. You can safely uninstall the CLI globally if you used that installation method.
128
106
 
129
107
  ## Options
130
108
 
131
109
  The CLI walks you through these choices interactively. Use `--yes` to skip prompts and accept all defaults.
132
110
 
133
- | Option | Choices | Default |
111
+ | **Option** | **Choices** | **Default** |
134
112
  | --------------------------- | --------------------------------------------- | -------------- |
135
113
  | **Language** | JavaScript, TypeScript | JavaScript |
136
114
  | **Module system** (JS only) | CommonJS, ES Modules | CommonJS |
@@ -143,7 +121,7 @@ The CLI walks you through these choices interactively. Use `--yes` to skip promp
143
121
 
144
122
  ### CLI flags
145
123
 
146
- | Flag | Effect |
124
+ | **Flag** | **Effect** |
147
125
  | -------------- | ----------------------------------------------------------- |
148
126
  | `--yes` | Accept all defaults, skip prompts |
149
127
  | `--dry-run` | Show the generation plan without writing files |
@@ -155,7 +133,7 @@ The CLI walks you through these choices interactively. Use `--yes` to skip promp
155
133
 
156
134
  ### Project structure (Simple architecture, JavaScript)
157
135
 
158
- ```
136
+ ```text
159
137
  my-api/
160
138
  ├── src/
161
139
  │ ├── app.js # Express app: middleware, routes, error handling
@@ -180,13 +158,13 @@ my-api/
180
158
  └── jest.config.js
181
159
  ```
182
160
 
183
- MVC architecture adds `controllers/`, `services/`, and `repositories/` directories with clear separation of concerns.
161
+ The MVC option organises the code into `controllers/`, `services/`, and `repositories/` to keep the business logic and data access separate.
184
162
 
185
163
  Postgres modes additionally include `db/schema.sql`, `db/seed.sql`, `src/db/` (connection pool), and setup scripts in `scripts/`. Docker mode adds a `compose.yaml`.
186
164
 
187
165
  ### Middleware
188
166
 
189
- Every generated project comes with these pre-configured:
167
+ The following middleware is pre-configured in every project:
190
168
 
191
169
  - **express.json()** - parses JSON request bodies
192
170
  - **cors** - enables cross-origin requests
@@ -205,7 +183,7 @@ Errors return a consistent JSON shape:
205
183
  }
206
184
  ```
207
185
 
208
- In development, a `stack` trace is included for debugging. In production, it's omitted.
186
+ In development, a `stack` trace is included for debugging. This is omitted in production.
209
187
 
210
188
  In PostgreSQL mode, duplicate values for unique fields (like `email`) return `409 Conflict` with a clear message instead of a generic `500`.
211
189
 
@@ -213,7 +191,7 @@ In PostgreSQL mode, duplicate values for unique fields (like `email`) return `40
213
191
 
214
192
  **JavaScript projects:**
215
193
 
216
- | Script | Command | Purpose |
194
+ | **Script** | **Command** | **Purpose** |
217
195
  | -------------- | --------------------------------------------------------------- | ---------------------------- |
218
196
  | `npm run dev` | `node --watch src/server.js` or `nodemon src/server.js` | Dev server with auto-restart |
219
197
  | `npm start` | `node src/server.js` | Production start |
@@ -224,7 +202,7 @@ Choosing `nodemon` adds it to `devDependencies` automatically.
224
202
 
225
203
  **TypeScript projects:**
226
204
 
227
- | Script | Command | Purpose |
205
+ | **Script** | **Command** | **Purpose** |
228
206
  | --------------- | ------------------------- | ---------------------------- |
229
207
  | `npm run dev` | `tsx watch src/server.ts` | Dev server with auto-restart |
230
208
  | `npm run build` | `tsc` | Compile to JavaScript |
@@ -234,7 +212,7 @@ Choosing `nodemon` adds it to `devDependencies` automatically.
234
212
 
235
213
  **Postgres modes also include:**
236
214
 
237
- | Script | Purpose |
215
+ | **Script** | **Purpose** |
238
216
  | ------------------- | ------------------------------------------------- |
239
217
  | `npm run db:create` | Create the database (psql mode only) |
240
218
  | `npm run db:setup` | Apply `db/schema.sql` |
@@ -245,29 +223,24 @@ Choosing `nodemon` adds it to `devDependencies` automatically.
245
223
 
246
224
  ### Tests
247
225
 
248
- Every generated project includes a working test suite using **Jest** and **Supertest**. Tests pass immediately after generation - no extra setup needed (in in-memory mode).
226
+ The project includes a functional test suite using Jest and Supertest. In-memory mode works out of the box - just run `npm test` immediately after generation.
249
227
 
250
228
  ## Database modes
251
229
 
252
230
  ### In-memory (default)
253
231
 
254
- Data lives in a plain JavaScript array. No database setup required. Data resets when the server restarts.
255
-
256
- Good for learning the project structure and getting something running fast. The code uses a repository pattern, so switching to a real database later is straightforward.
232
+ Data is stored in a simple JavaScript array, so you don't need to install or configure anything. This is useful for prototyping, though data will reset every time the server restarts. Because the project uses a repository pattern, you can swap this for a real database later without having to refactor your routes.
257
233
 
258
234
  ### Postgres (psql)
259
235
 
260
- For developers who already have PostgreSQL installed locally. The generated project includes:
261
-
262
- - `pg` as a dependency with a connection pool
263
- - `db/schema.sql` and `db/seed.sql` for table creation and sample data
264
- - Node scripts for database management (`db:create`, `db:setup`, `db:seed`, `db:reset`) using the `pg` library
265
- - A project-specific database name derived from your project name (e.g. `my-api` → `my_api_dev`)
266
- - `DATABASE_URL` pre-configured with your OS username
236
+ If you have PostgreSQL running locally, this mode sets up everything you need to connect your app to a real database. The generated project includes:
267
237
 
268
- > Note: Local dev defaults are for convenience only; update DB credentials in `.env` before deployment.
238
+ - `pg` (node-postgres) with a pre-configured connection pool.
239
+ - `db/schema.sql` and `db/seed.sql` for your initial tables and test data.
240
+ - Management scripts (`db:setup`, `db:reset`, etc.) so you don't have to jump into the terminal to run SQL manually.
241
+ - A `DATABASE_URL` in your `.env` pre-filled with your OS username and a database name derived from your project.
269
242
 
270
- **Requires:** PostgreSQL installed and running locally.
243
+ **To get started:**
271
244
 
272
245
  ```bash
273
246
  # After generation
@@ -281,11 +254,9 @@ The generated README includes OS-specific PostgreSQL installation and role setup
281
254
 
282
255
  ### Postgres (Docker)
283
256
 
284
- For developers who have Docker but don't want to install PostgreSQL locally. The generated project includes:
257
+ If you prefer Docker to avoid a local installation, this mode provides a `compose.yaml` that runs PostgreSQL on port 5433 (avoiding conflicts with any local Postgres you might have).
285
258
 
286
- - A `compose.yaml` that runs PostgreSQL in a container (port 5433 to avoid conflicts with local installs)
287
- - Node-based setup scripts using the `pg` library - no `psql` CLI needed on your machine
288
- - A retry helper that waits for the database container to be ready before running setup
259
+ It includes a **retry helper** in the setup scripts. This solves the common issue where scripts fail because the database container isn't fully "ready" to accept connections yet.
289
260
 
290
261
  ```bash
291
262
  # After generation
@@ -300,36 +271,26 @@ npm run db:down # Stop and remove container + data
300
271
 
301
272
  ## Educational comments
302
273
 
303
- Enabled by default. The generated code includes short inline comments explaining _why_ things are done a certain way:
274
+ You can enable inline comments that explain the 'why' behind the code. These are designed to be short and useful, covering things like:
304
275
 
305
- ```javascript
306
- // Parse JSON request bodies so route handlers can read data from req.body.
307
- // Without this middleware, req.body is undefined for JSON requests.
308
- app.use(express.json());
309
-
310
- // Set common HTTP security headers.
311
- // Helmet applies safe defaults that reduce exposure to common web attacks.
312
- app.use(helmet());
313
- ```
314
-
315
- These comments cover middleware, routing, error handling, database scripts, and architecture patterns. They teach without getting in the way. Turn them off during generation if you prefer clean code.
276
+ - Why we use `express.json()` and what happens if you forget it.
277
+ - Why `helmet` is included for security.
278
+ - How the repository pattern simplifies your data logic.
316
279
 
317
280
  ## Design decisions
318
281
 
319
- **Opinionated defaults, easy to change.** The tool picks Jest, morgan, cors, helmet, and ESLint for you so the project works immediately. The generated README explains each choice, and everything is easy to swap out.
320
-
321
- **Module system is a choice (JS only).** CommonJS is the default because most Express tutorials use it. ES Modules are available if you prefer modern `import`/`export` syntax. TypeScript projects always use ESM-style imports that compile to CommonJS.
282
+ **Opinionated but swappable.** The tool uses a standard stack (Jest, Morgan, Helmet, and ESLint) so projects are functional immediately. There is no complex logic connecting these tools, so they are easy to swap out if a different library is preferred.
322
283
 
323
- **Dev watcher is a choice (JS only).** `node --watch` is built-in and needs no extra dependency (requires Node >= 20.13). `nodemon` is the alternative for developers who already use it. TypeScript projects always use `tsx watch`.
284
+ **Module system choice.** JavaScript projects allow choosing between CommonJS and ES Modules. TypeScript projects use ESM-style imports that compile to clean CommonJS.
324
285
 
325
- **No extras you didn't ask for.** No auth, no ORM, no migrations, no rate limiting, no OpenAPI. Those are decisions worth making when you actually need them.
286
+ **Auth, ORMs, and OpenAPI.** These are not included in the current templates. Since these are major architectural decisions, they are best left to the developer to decide based on specific project needs. These may be added as configurable options in later versions.
326
287
 
327
288
  ## Requirements
328
289
 
329
- - **Node.js >= 20** (>= 20.13 if choosing `node --watch` as the JavaScript dev watcher)
330
- - **npm** (ships with Node)
331
- - **Docker** (only for Postgres Docker mode)
332
- - **PostgreSQL** (only for Postgres psql mode)
290
+ - **Node.js >= 20**
291
+ - **npm** (comes with Node)
292
+ - **Docker** (only if using Docker DB mode)
293
+ - **PostgreSQL** (only if using local psql mode)
333
294
 
334
295
  ## Built with
335
296
 
@@ -342,7 +303,7 @@ These comments cover middleware, routing, error handling, database scripts, and
342
303
 
343
304
  **Generated projects use:**
344
305
 
345
- - Express 4
306
+ - Express 5
346
307
  - Jest + Supertest for testing
347
308
  - ESLint for linting
348
309
  - `@swc/jest` for TypeScript test transforms
@@ -350,7 +311,7 @@ These comments cover middleware, routing, error handling, database scripts, and
350
311
 
351
312
  ## Contributing
352
313
 
353
- Contributions are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
314
+ If you find a bug or have an idea for a template, feel free to open an issue or a PR. See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
354
315
 
355
316
  ```bash
356
317
  git clone https://github.com/alexmc2/create-express-api-starter.git
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexmc2/create-express-api-starter",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Interactive CLI to scaffold API-first Express backend projects",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -51,6 +51,7 @@ Express API starter generated by `@alexmc2/create-express-api-starter`.
51
51
  ├── .eslintrc.cjs
52
52
  ├── package.json
53
53
  ├── tsconfig.json
54
+ ├── tsconfig.eslint.json
54
55
  └── jest.config.js
55
56
  ```
56
57
 
@@ -47,6 +47,7 @@ Express API starter generated by `@alexmc2/create-express-api-starter`.
47
47
  ├── .eslintrc.cjs
48
48
  ├── package.json
49
49
  ├── tsconfig.json
50
+ ├── tsconfig.eslint.json
50
51
  └── jest.config.js
51
52
  ```
52
53