exp-node-server 2.0.0 → 2.1.0
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 +83 -3
- package/dist/cli.js +191 -103
- package/package.json +1 -1
- package/templates/mongoose/.prettierignore +1 -0
- package/templates/mongoose/_gitignore +4 -1
- package/templates/mongoose/eslint.config.js +1 -1
- package/templates/mongoose/package-lock.json +5 -16
- package/templates/mongoose/package.json +1 -2
- package/templates/mongoose/readme.md +3 -0
- package/templates/mongoose/src/app/queues/agenda.ts +16 -4
- package/templates/mongoose/src/app/queues/email.queue.ts +34 -6
- package/templates/mongoose/src/app/queues/index.ts +10 -6
- package/templates/mongoose/tests/queues/email.queue.test.ts +137 -0
- package/templates/prisma/.prettierignore +2 -1
- package/templates/prisma/_gitignore +4 -1
- package/templates/prisma/eslint.config.js +1 -1
- package/templates/prisma/package-lock.json +5 -16
- package/templates/prisma/package.json +1 -2
- package/templates/prisma/readme.md +9 -0
- package/templates/prisma/src/app/queues/boss.ts +28 -3
- package/templates/prisma/src/app/queues/email.queue.ts +23 -8
- package/templates/prisma/src/app/queues/index.ts +16 -7
- package/templates/prisma/src/app/queues/maintenance.queue.ts +2 -2
- package/templates/prisma/tests/queues/email.queue.test.ts +162 -0
package/README.md
CHANGED
|
@@ -25,6 +25,26 @@ This tool helps developers quickly scaffold `clean`, `modular` `Express` APIs wi
|
|
|
25
25
|
- 🔄 Add modules anytime
|
|
26
26
|
- 📦 Zero boilerplate setup
|
|
27
27
|
|
|
28
|
+
## 📋 Requirements
|
|
29
|
+
|
|
30
|
+
- Node.js **20.17+** to run the CLI; generated projects need Node.js **22.12+**
|
|
31
|
+
- Docker (or your own database): PostgreSQL for Prisma, MongoDB for Mongoose
|
|
32
|
+
|
|
33
|
+
## 📥 Installation
|
|
34
|
+
|
|
35
|
+
No install needed: `npx` always runs the latest version (recommended).
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx exp-node-server --help
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Or install it globally to use `exp-node-server` directly:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm install -g exp-node-server
|
|
45
|
+
exp-node-server --version
|
|
46
|
+
```
|
|
47
|
+
|
|
28
48
|
## 📦 Quick Start
|
|
29
49
|
|
|
30
50
|
Run directly using npx (recommended):
|
|
@@ -44,7 +64,38 @@ Then:
|
|
|
44
64
|
```bash
|
|
45
65
|
cd my-api
|
|
46
66
|
npm install
|
|
47
|
-
|
|
67
|
+
cp .env.example .env # fill in the secrets (openssl rand -hex 32)
|
|
68
|
+
docker compose up -d # starts PostgreSQL / MongoDB
|
|
69
|
+
npm run db:migrate # Prisma only
|
|
70
|
+
npm run dev # http://localhost:5000, docs at /docs
|
|
71
|
+
npm test
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### What you get
|
|
75
|
+
|
|
76
|
+
```text
|
|
77
|
+
my-api/
|
|
78
|
+
├── src/
|
|
79
|
+
│ ├── app.ts # express app: helmet, cors, rate limit, routes
|
|
80
|
+
│ ├── server.ts # connects the database, starts queues, graceful shutdown
|
|
81
|
+
│ ├── routes.ts # module routers (generated modules are added here)
|
|
82
|
+
│ ├── swaggerOptions.ts # API docs (generated modules are added here)
|
|
83
|
+
│ └── app/
|
|
84
|
+
│ ├── configs/ # env vars, validated with zod on startup
|
|
85
|
+
│ ├── middlewares/ # auth, validation, rate limiting, uploads, errors
|
|
86
|
+
│ ├── modules/
|
|
87
|
+
│ │ ├── account/ # sign up/in, OTP, refresh tokens, password reset
|
|
88
|
+
│ │ └── profile/ # profile + photo upload (Cloudinary)
|
|
89
|
+
│ ├── passport-js/ # social login (Google, Facebook, GitHub, X, LinkedIn, Discord)
|
|
90
|
+
│ ├── queues/ # background email jobs (pg-boss / Agenda, no Redis)
|
|
91
|
+
│ ├── templates/ # email templates
|
|
92
|
+
│ └── utils/
|
|
93
|
+
├── tests/
|
|
94
|
+
│ ├── routes/ # supertest suites, one per module
|
|
95
|
+
│ └── helpers/
|
|
96
|
+
├── prisma/schema/ # Prisma only: one .prisma file per model
|
|
97
|
+
├── docker-compose.yml
|
|
98
|
+
└── .env.example
|
|
48
99
|
```
|
|
49
100
|
|
|
50
101
|
## 🧩 Generate a Module
|
|
@@ -83,7 +134,22 @@ including the 404s, and passes as generated:
|
|
|
83
134
|
npm test -- tests/routes/order.test.ts
|
|
84
135
|
```
|
|
85
136
|
|
|
86
|
-
|
|
137
|
+
Generated modules start with an example `name` field, from the validation to the
|
|
138
|
+
database schema and the tests, so data flows end to end right away. Rename it or add
|
|
139
|
+
your fields in the same places, and update `createPayload` / `updatePayload` at the
|
|
140
|
+
top of the test. These are starter tests: extend them with your business rules.
|
|
141
|
+
|
|
142
|
+
### Protected routes
|
|
143
|
+
|
|
144
|
+
Generated routes are **public** by default. To require a signed-in user on every
|
|
145
|
+
route:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
npx exp-node-server -g order --auth
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
The generated test then also checks that anonymous requests get a 401. To limit a
|
|
152
|
+
route to admins, change `auth()` to `auth('ADMIN')` in `order.route.ts`.
|
|
87
153
|
Mongoose tests run against an in-memory MongoDB; Prisma tests use the Prisma mock in
|
|
88
154
|
`tests/helpers/prisma.ts`. Module names whose path is already taken (e.g. `auth`) are
|
|
89
155
|
refused.
|
|
@@ -92,7 +158,7 @@ refused.
|
|
|
92
158
|
|
|
93
159
|
```text
|
|
94
160
|
npx exp-node-server create <project-name> [--template <mongoose|prisma>]
|
|
95
|
-
npx exp-node-server generate <module-name> [--force]
|
|
161
|
+
npx exp-node-server generate <module-name> [--auth] [--force]
|
|
96
162
|
|
|
97
163
|
Commands
|
|
98
164
|
create, -c <name> Create a new project from a template
|
|
@@ -100,6 +166,7 @@ Commands
|
|
|
100
166
|
|
|
101
167
|
Options
|
|
102
168
|
-t, --template <name> Template to use with create (mongoose | prisma)
|
|
169
|
+
-a, --auth Generated routes require a signed-in user (default: public)
|
|
103
170
|
-f, --force Overwrite an existing module when generating
|
|
104
171
|
-h, --help Show help
|
|
105
172
|
-v, --version Show version
|
|
@@ -108,6 +175,19 @@ Options
|
|
|
108
175
|
- Project names are lowercased and spaces become dashes (`My API` → `my-api`).
|
|
109
176
|
- Module names are lowercased and spaces/dashes become underscores (`order-item` → `order_item`).
|
|
110
177
|
|
|
178
|
+
### Safety
|
|
179
|
+
|
|
180
|
+
- **All or nothing:** a module is generated in one step. If anything fails (e.g. a
|
|
181
|
+
file can't be written), the project is left exactly as it was.
|
|
182
|
+
- **`--force` keeps backups:** files it overwrites are copied first to
|
|
183
|
+
`.exp-node-server/backups/<timestamp>/` (ignored by git, ESLint and Prettier).
|
|
184
|
+
Files that wouldn't change are left alone.
|
|
185
|
+
- **No clashes:** a module name whose URL is already used by another router (e.g.
|
|
186
|
+
`auth`) is refused.
|
|
187
|
+
- **Validated input only:** generated services receive `req.body` after
|
|
188
|
+
`RequestValidator` parsed it with the module's zod schema, so unknown fields are
|
|
189
|
+
dropped. Payload types come from that schema (`z.infer`).
|
|
190
|
+
|
|
111
191
|
## 📁 Generated Module Structure
|
|
112
192
|
|
|
113
193
|
Each module follows a clean structure:
|