express-generator-typescript 2.9.0 → 2.9.1

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
@@ -1,17 +1,198 @@
1
- <p align="center">
2
- <img alt="express-generator-typescript" src="https://github.com/seanpmaxwell/express-generator-typescript/raw/main/assets/express-typescript.png" width="420">
3
- </p>
4
-
5
- # express-generator-typescript
6
-
7
- [![npm version](https://img.shields.io/npm/v/express-generator-typescript?logo=npm&label=npm)](https://www.npmjs.com/package/express-generator-typescript)
8
- [![npm downloads](https://img.shields.io/npm/dm/express-generator-typescript?color=orange)](https://www.npmjs.com/package/express-generator-typescript)
9
- [![License](https://img.shields.io/npm/l/express-generator-typescript)](https://github.com/seanpmaxwell/express-generator-typescript/blob/main/LICENSE)
10
-
11
- Command line tool which generates production-ready express templates with TypeScript baked in. Spin up a web server in seconds that follows the [TypeScript best practices](https://github.com/seanpmaxwell/Typescript-Best-Practices/blob/main/README.md).
12
- <br/>
13
-
14
-
15
- ## Documenation
16
-
17
- Please refer to the official <a href="https://github.com/seanpmaxwell/express-generator-typescript">github repo</a> for the most up-to-date documentation.
1
+ <p align="center">
2
+ <img alt="express-generator-typescript" src="https://github.com/seanpmaxwell/express-generator-typescript/raw/main/assets/express-typescript.png" width="420">
3
+ </p>
4
+
5
+ # express-generator-typescript
6
+
7
+ [![npm version](https://img.shields.io/npm/v/express-generator-typescript?logo=npm&label=npm)](https://www.npmjs.com/package/express-generator-typescript)
8
+ [![npm downloads](https://img.shields.io/npm/dm/express-generator-typescript?color=orange)](https://www.npmjs.com/package/express-generator-typescript)
9
+ [![License](https://img.shields.io/npm/l/express-generator-typescript)](https://github.com/seanpmaxwell/express-generator-typescript/blob/main/LICENSE)
10
+
11
+ Command line tool which generates production-ready express templates with TypeScript baked in. Spin up a web server in seconds that follows the [TypeScript best practices](https://github.com/seanpmaxwell/Typescript-Best-Practices/blob/main/README.md).
12
+
13
+ <p align="center">· · ·</p>
14
+
15
+ ## 🧭 Overview
16
+
17
+ `express-generator-typescript` creates a new Express application similar to the classic `express-generator` package, but the generated project is fully wired for TypeScript. You get strict typing, linting, hot reloading, production builds, testing utilities, and sane defaults that focus on APIs (no view engine or opinionated ORM). Path aliases are preconfigured through `tsconfig-paths` and `_moduleAliases`, so referencing modules stays clean even as the app grows.
18
+
19
+ <p align="center">· · ·</p>
20
+
21
+ ## ✨ Features
22
+
23
+ - **TypeScript-first** – strict compiler settings, linting, and sensible tsconfig defaults ready to go.
24
+ - **API-centric** – no view engine or extra dependencies; ideal for SPAs, mobile backends, or services.
25
+ - **Productivity tooling** – includes nodemon, ts-node, hot reload scripts, Vitest, ESLint, and production builds.
26
+ - **Path aliases** – `@src/*` aliases configured in `tsconfig.json` (and `_moduleAliases` in `package.json` for production) so you can import modules cleanly.
27
+ - **Keeps dependencies lean** – no bundled ORM or UI layers; only the essentials for Express + TS development.
28
+
29
+ <p align="center">· · ·</p>
30
+
31
+ ## 📦 Installation
32
+
33
+ Requires Node.js 22.12 or newer.
34
+
35
+ ```bash
36
+ npx express-generator-typescript
37
+ # or install globally
38
+ npm install -g express-generator-typescript
39
+ ```
40
+
41
+ <p align="center">· · ·</p>
42
+
43
+ ## ⚡ Quick Start
44
+
45
+ ```bash
46
+ # generate a project (defaults to express-gen-ts)
47
+ npx express-generator-typescript my-api
48
+
49
+ cd my-api
50
+
51
+ # start developing at http://localhost:3000
52
+ npm run dev
53
+ ```
54
+
55
+ Use `--use-yarn` if you prefer Yarn over npm. If you omit the project name, the generator creates `express-gen-ts`.
56
+
57
+ <p align="center">· · ·</p>
58
+
59
+ ## 🖥️ CLI Options
60
+
61
+ | Option | Description |
62
+ | ----------------- | --------------------------------------------------------------------------- |
63
+ | `project name` | Folder to create. Defaults to `express-gen-ts` if omitted. |
64
+ | `--use-yarn` | Installs dependencies with Yarn instead of npm. |
65
+ | `--force` | Writes into the target folder even if it is not empty (existing files with the same names are overwritten). |
66
+ | `-h`, `--help` | Shows usage. |
67
+ | `-v`, `--version` | Shows the generator version. |
68
+
69
+ > The generator refuses to write into a folder that already has files in it, so it can't overwrite your work by accident.
70
+
71
+ <p align="center">· · ·</p>
72
+
73
+ ## 🧩 Generated Template
74
+
75
+ The generated template is a CRUD app for the `User` record to demonstrate model, services, and routing patterns in Express + TypeScript. Commands for linting, transpiling, formatting, and hot-reloading are all configured for you.
76
+
77
+ ### Available `package.json` Scripts
78
+
79
+ - `npm run dev` – Run the server in dev mode with live reload and browser refresh.
80
+ - `npm run test` - Run tests with vitest.
81
+ - `npm run test -- users.test.ts` – Target a single test file.
82
+ - `npm run lint` – Run ESLint checks.
83
+ - `npm run format` - Run prettier.
84
+ - `npm run build` – Compile the project for production.
85
+ - `npm start` – Serve the built project.
86
+ - `npm run typecheck` – Run the TypeScript compiler without emitting files.
87
+ - `npm run install:clean` – Delete `node_modules` and the lockfile, then reinstall.
88
+
89
+ ### Architecture
90
+
91
+ Because this is a small CRUD app, **layered** is the architectural pattern of choice. However, you should consider switching to a **domain-based** layout if you plan on scaling. There is a good tutorial [here](https://github.com/seanpmaxwell/Typescript-Best-Practices/tree/main?tab=readme-ov-file#architecture) in the _Typescript Best Practices README_ about architectural patterns with TypeScript.
92
+
93
+ Layers explained:
94
+ ```yml
95
+ - src/ <-- source code
96
+ - common/
97
+ - constants/
98
+ - Paths.ts <-- Single source of truth for all API routes
99
+ - routes/ <-- extracting and validating values from express Request/Response objects
100
+ - services/ <-- Business logic (where everything comes together)
101
+ - repos/ <-- Talking to the database layer
102
+ - models/ <-- For describing/handling objects representing database records
103
+ - tests/ <-- unit-tests
104
+ ```
105
+
106
+ <p align="center">· · ·</p>
107
+
108
+ ## Notes for VSCode users
109
+
110
+ <details>
111
+ <summary>Format on save</summary>
112
+
113
+ The generated template uses `eslint`+`prettier`, so if you want features like _formatting on save_, you need to make sure to install the prettier extension for VSCode and set it as your default formatter in `.vscode/setting.json`:
114
+
115
+ ```json
116
+ // .vscode/settings.json
117
+ {
118
+ "editor.minimap.enabled": false,
119
+ "editor.rulers": [80],
120
+ "editor.tabSize": 2,
121
+
122
+ "workbench.sideBar.location": "right",
123
+ "workbench.editor.empty.hint": "hidden",
124
+
125
+ // Formatting: Prettier only
126
+ "editor.formatOnSave": true,
127
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
128
+
129
+ // ESLint: linting only (NO formatting)
130
+ "eslint.format.enable": false,
131
+ "eslint.nodePath": "node_modules",
132
+ "eslint.validate": ["javascript", "typescript", "typescriptreact"],
133
+
134
+ // Run ESLint fixes (non-formatting) on save
135
+ "editor.codeActionsOnSave": {
136
+ "source.fixAll.eslint": "explicit"
137
+ },
138
+
139
+ // Language overrides (keep Prettier)
140
+ "[javascript]": {
141
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
142
+ },
143
+ "[typescript]": {
144
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
145
+ },
146
+ "[json]": {
147
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
148
+ },
149
+
150
+ // JSDoc noise reduction
151
+ "javascript.suggest.completeJSDocs": false,
152
+ "javascript.suggest.jsdoc.generateReturns": false,
153
+ "typescript.suggest.completeJSDocs": false,
154
+ "typescript.suggest.jsdoc.generateReturns": false
155
+ }
156
+ ```
157
+
158
+ </details>
159
+
160
+ <details>
161
+ <summary>Debugging</summary>
162
+
163
+ If you want to debug in VSCode with breakpoints you need to start the processes through `.vscode/launch.json`:
164
+
165
+ ```json
166
+ // .vscode/launch.json
167
+ {
168
+ "version": "0.2.0",
169
+ "configurations": [
170
+ {
171
+ "name": "Dev - ts-node",
172
+ "type": "node",
173
+ "request": "launch",
174
+ "runtimeExecutable": "npm",
175
+ "runtimeArgs": ["run", "dev"],
176
+ "skipFiles": ["<node_internals>/**"],
177
+ "console": "integratedTerminal"
178
+ },
179
+ {
180
+ "name": "Test - Vitest",
181
+ "type": "node",
182
+ "request": "launch",
183
+ "runtimeExecutable": "npm",
184
+ "runtimeArgs": ["run", "test"],
185
+ "skipFiles": ["<node_internals>/**"],
186
+ "console": "integratedTerminal"
187
+ }
188
+ ]
189
+ }
190
+ ```
191
+
192
+ </details>
193
+
194
+ <p align="center">· · ·</p>
195
+
196
+ ## 📄 License
197
+
198
+ MIT © [seanpmaxwell1](LICENSE)
@@ -29,12 +29,11 @@
29
29
  "jet-env": "^1.1.6",
30
30
  "jet-id": "^1.3.1",
31
31
  "jet-logger": "3.0.0",
32
- "jet-paths": "^4.0.1",
32
+ "jet-paths": "^4.0.2",
33
33
  "jet-validators": "^2.3.1",
34
34
  "jsonfile": "^6.2.1",
35
35
  "module-alias": "^2.3.4",
36
- "morgan": "^1.12.1",
37
- "tspo": "^1.0.7"
36
+ "morgan": "^1.12.1"
38
37
  },
39
38
  "devDependencies": {
40
39
  "@eslint/js": "^10.0.1",
@@ -386,8 +386,13 @@ const HttpStatusCodes = {
386
386
  } as const;
387
387
 
388
388
  // ========================================================================= //
389
- // EXPORT //
389
+ // TYPES //
390
390
  // ========================================================================= //
391
391
 
392
392
  type HttpStatusCodes = ValueOf<typeof HttpStatusCodes>;
393
+
394
+ // ========================================================================= //
395
+ // EXPORT //
396
+ // ========================================================================= //
397
+
393
398
  export default HttpStatusCodes;
@@ -1,5 +1,5 @@
1
1
  import jetEnv, { num } from 'jet-env';
2
- import tspo from 'tspo';
2
+ import { ValueOf } from '../types/utility-types';
3
3
 
4
4
  // ========================================================================= //
5
5
  // CONSTANTS //
@@ -11,18 +11,21 @@ export const NodeEnvs = {
11
11
  TEST: 'test',
12
12
  PRODUCTION: 'production',
13
13
  } as const;
14
+ export type NodeEnvs = ValueOf<typeof NodeEnvs>;
14
15
 
15
16
  // ========================================================================= //
16
17
  // EXEC //
17
18
  // ========================================================================= //
18
19
 
19
- const EnvVars = jetEnv({
20
- NodeEnv: (v) => tspo.isValue(NodeEnvs, v),
20
+ // Setup the is `NodeEnvs` validator
21
+ const isNodeEnv = (() => {
22
+ const vals = Object.values(NodeEnvs);
23
+ const valsFin = vals.map((item) => item.toLowerCase());
24
+ const set = new Set(valsFin);
25
+ return (val: unknown): val is NodeEnvs => set.has(val as NodeEnvs);
26
+ })();
27
+
28
+ export const EnvVars = jetEnv({
29
+ NodeEnv: isNodeEnv,
21
30
  Port: num,
22
31
  });
23
-
24
- // ========================================================================= //
25
- // EXPORT //
26
- // ========================================================================= //
27
-
28
- export default EnvVars;
@@ -1,6 +1,6 @@
1
1
  import logger from 'jet-logger';
2
2
 
3
- import EnvVars from './common/constants/env';
3
+ import { EnvVars } from './common/constants/env-inv';
4
4
  import server from './server';
5
5
 
6
6
  // ========================================================================= //
@@ -2,7 +2,7 @@ import fs from 'fs/promises';
2
2
  import jsonfile from 'jsonfile';
3
3
  import path from 'path';
4
4
 
5
- import EnvVars, { NodeEnvs } from '@src/common/constants/env';
5
+ import { EnvVars, NodeEnvs } from '@src/common/constants/env-inv';
6
6
  import { IUser } from '@src/models/User.model';
7
7
 
8
8
  // ========================================================================= //
@@ -9,7 +9,7 @@ import Paths from '@src/common/constants/Paths';
9
9
  import { RouteError } from '@src/common/utils/route-errors';
10
10
  import BaseRouter from '@src/routes/apiRouter';
11
11
 
12
- import EnvVars, { NodeEnvs } from './common/constants/env';
12
+ import { EnvVars, NodeEnvs } from './common/constants/env-inv';
13
13
 
14
14
  // ========================================================================= //
15
15
  // EXEC //
package/package.json CHANGED
@@ -1,15 +1,11 @@
1
1
  {
2
2
  "name": "express-generator-typescript",
3
- "version": "2.9.0",
3
+ "version": "2.9.1",
4
4
  "description": "Generate new Express applications similar to express-generate which but sets it up to use TypeScript instead",
5
5
  "scripts": {
6
6
  "commit": "git add -A && git commit -m \"dev commit\"",
7
7
  "commit:push": "npm run commit && git push",
8
8
  "install:clean": "rm -rf node_modules && rm -rf package-lock.json && npm i",
9
- "prepack": "npm run readme:swap",
10
- "postpack": "npm run readme:restore",
11
- "readme:swap": "node scripts/readme.js swap",
12
- "readme:restore": "node scripts/readme.js restore",
13
9
  "test": "node --test \"tests/**/*.test.js\"",
14
10
  "test:e2e": "node scripts/e2e.js"
15
11
  },