create-express-new 0.0.0-stage → 1.0.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/CHANGELOG.md +113 -0
- package/LICENSE +24 -0
- package/README.md +281 -2
- package/bin/express-cli.js +577 -0
- package/lib/app.js +607 -0
- package/lib/prompts.js +338 -0
- package/lib/wizard.js +397 -0
- package/package.json +65 -4
- package/templates/app/Dockerfile.ejs +64 -0
- package/templates/app/app.js.ejs +163 -0
- package/templates/app/csrf.js.ejs +21 -0
- package/templates/app/dockerignore +15 -0
- package/templates/app/env.example.ejs +40 -0
- package/templates/app/eslint.config.js.ejs +28 -0
- package/templates/app/gitignore +22 -0
- package/templates/app/npmrc +8 -0
- package/templates/app/pnpm-workspace.yaml +24 -0
- package/templates/app/routes/index.js.ejs +22 -0
- package/templates/app/routes/uploads.js.ejs +94 -0
- package/templates/app/routes/users.js.ejs +42 -0
- package/templates/app/test/app.test.js.ejs +199 -0
- package/templates/app/www.js.ejs +46 -0
- package/templates/public/index.html +13 -0
- package/templates/public/stylesheets/style.css +8 -0
- package/templates/versions.json +49 -0
- package/templates/views/error.ejs +12 -0
- package/templates/views/error.hbs +3 -0
- package/templates/views/error.pug +6 -0
- package/templates/views/error.twig +7 -0
- package/templates/views/index.ejs +11 -0
- package/templates/views/index.hbs +2 -0
- package/templates/views/index.pug +5 -0
- package/templates/views/index.twig +6 -0
- package/templates/views/layout.hbs +10 -0
- package/templates/views/layout.pug +7 -0
- package/templates/views/layout.twig +10 -0
- package/templates/views/new-user.ejs +18 -0
- package/templates/views/new-user.hbs +9 -0
- package/templates/views/new-user.pug +13 -0
- package/templates/views/new-user.twig +13 -0
- package/templates/views/uploads.ejs +16 -0
- package/templates/views/uploads.hbs +7 -0
- package/templates/views/uploads.pug +10 -0
- package/templates/views/uploads.twig +11 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format is based on
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project follows
|
|
5
|
+
[Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [1.0.0] - 2026-10-10
|
|
10
|
+
|
|
11
|
+
The first release of `create-express-new`, a fork of
|
|
12
|
+
[`express-generator`](https://github.com/expressjs/generator) 4.16.1 reimagined for Express 5 and
|
|
13
|
+
current Node.js. See [Changes from express-generator](docs/changes-from-express-generator.md) for
|
|
14
|
+
the full list and a table for migrating commands.
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- `npm create express-new@latest`, with an interactive wizard when run without arguments in a
|
|
19
|
+
terminal; Esc goes back, and it shows the equivalent command and offers to install the dependencies
|
|
20
|
+
- ES module output by default, `--cjs` for CommonJS and `--ts` for TypeScript, run directly by
|
|
21
|
+
Node.js with no build step
|
|
22
|
+
- `--api` for JSON APIs, with JSON 404 and error responses that hide server error details in
|
|
23
|
+
production
|
|
24
|
+
- `--helmet`, `--compression`, `--cookies` and `--cors` for opt-in middleware
|
|
25
|
+
- `--docker` for a production Dockerfile running as the `node` user, with a `HEALTHCHECK`
|
|
26
|
+
- `--lint` for ESLint, including typescript-eslint for TypeScript apps
|
|
27
|
+
- A `GET /health` endpoint, `.env` loading with a generated `.env.example`, an `npm run dev` script
|
|
28
|
+
using `node --watch`, and a `node:test` test suite in every app
|
|
29
|
+
- Graceful shutdown on SIGINT and SIGTERM, and a modern `.gitignore` (skip it with `--no-git`)
|
|
30
|
+
- `--rate-limit` adds express-rate-limit, limiting each client to 100 requests every 15 minutes
|
|
31
|
+
(`RATE_LIMIT_MAX`, `RATE_LIMIT_WINDOW_MS`), after static files and never on `/health`
|
|
32
|
+
- `--session` adds express-session for web apps, with `SameSite=Lax` cookies that are `Secure` over
|
|
33
|
+
HTTPS, and refuses to start in production without `SESSION_SECRET`
|
|
34
|
+
- `--csrf` adds csrf-sync CSRF protection to apps with `--session` and a view engine, with the token
|
|
35
|
+
in views as `csrfToken` and in a `csrf-token` meta tag in the page layout
|
|
36
|
+
- `--uploads` adds multer and a `POST /uploads` route for web apps and JSON APIs, saving one file of
|
|
37
|
+
up to 5 MB (`UPLOAD_MAX_SIZE`) of an allowed type in an ignored `uploads/` folder, with an upload
|
|
38
|
+
form in apps with views; with `--csrf` it checks the token before saving the file, and with
|
|
39
|
+
`--docker` the image has a writable `uploads` folder
|
|
40
|
+
- With `--csrf`, an example form at `/users/new` and CSRF setup in its own `csrf.js`
|
|
41
|
+
- `--logger=pino` logs requests as JSON with pino-http instead of morgan, pretty printed by the
|
|
42
|
+
`dev` script
|
|
43
|
+
- `TRUST_PROXY` sets the proxies the app trusts, for apps with `--rate-limit` or `--session`
|
|
44
|
+
- The wizard offers express-rate-limit and express-session (for web apps) with the other middleware,
|
|
45
|
+
asks about CSRF protection when sessions are chosen, and asks which request logger to use
|
|
46
|
+
- `--keep-config` keeps existing config files (`.env.example`, `Dockerfile`, `.dockerignore`,
|
|
47
|
+
`tsconfig.json`, `eslint.config.*`) when generating into a non-empty directory
|
|
48
|
+
- The wizard lists the existing files an app would overwrite and asks whether to overwrite them,
|
|
49
|
+
keep the config files or cancel
|
|
50
|
+
- The wizard's directory prompt hints that `.` is the current directory
|
|
51
|
+
- `--pm` sets the package manager an app requires, `pnpm` (the default) or `npm`, as
|
|
52
|
+
`devEngines.packageManager` in `package.json`, so other package managers refuse to install the
|
|
53
|
+
app or run its scripts
|
|
54
|
+
- Settings that protect installs from compromised packages in every app: `pnpm-workspace.yaml` for
|
|
55
|
+
pnpm apps (new releases wait 3 days, install scripts of dependencies are not run, dependencies of
|
|
56
|
+
dependencies cannot come from git or URLs, releases with weaker proof of origin than earlier ones
|
|
57
|
+
are refused, and the pnpm version recorded in `pnpm-lock.yaml` is the one that runs) and `.npmrc`
|
|
58
|
+
for npm apps (new releases wait 3 days; npm 12 does not run install scripts or allow git
|
|
59
|
+
dependencies by default); `--keep-config` keeps existing ones
|
|
60
|
+
- The wizard asks which package manager the app requires and installs dependencies with it
|
|
61
|
+
- `npm run versions` reports a version floor released under 3 days ago as too new for generated apps
|
|
62
|
+
to install, and `--update` lowers it; floors are only raised to releases at least 7 days old
|
|
63
|
+
|
|
64
|
+
### Changed
|
|
65
|
+
|
|
66
|
+
- Generates Express 5 apps with current versions of every dependency; apps require Node.js 22.9 or
|
|
67
|
+
newer (22.18 for TypeScript)
|
|
68
|
+
- The default view engine is pug (was jade); `--view=jade` warns and generates pug
|
|
69
|
+
- `bin/www` is now `bin/www.js`, a short script built on `app.listen()`
|
|
70
|
+
- cookie-parser is no longer included by default; use `--cookies`
|
|
71
|
+
- The generator is an ES module with a single dependency (ejs)
|
|
72
|
+
- Apps require pnpm 11 or newer by default, and `npm install` is refused in them; pass
|
|
73
|
+
`--pm=npm` for an app that requires npm, which now has to be npm 12 or newer
|
|
74
|
+
- The usage, next steps, `.env.example` and the wizard's equivalent command name the app's package
|
|
75
|
+
manager, such as `pnpm create express-new@latest my-app --ts` and `pnpm dev`
|
|
76
|
+
- `--docker` images install dependencies with the app's package manager, at a fixed version, in a
|
|
77
|
+
build stage of their own, so the package manager is not in the final image
|
|
78
|
+
- Every app's error handler logs server errors (5xx) with `console.error`, which no error handler
|
|
79
|
+
did before, so a 500 only showed as a status in the request log
|
|
80
|
+
- An existing `.gitignore` gets the missing lines added instead of being replaced
|
|
81
|
+
- Existing files with the same contents are left alone, logged as `identical`
|
|
82
|
+
- The command line lists the files it would overwrite before asking to continue in a non-empty
|
|
83
|
+
directory
|
|
84
|
+
- A warning lists existing files the new app does not use but other options generate (code in the
|
|
85
|
+
other language, the other ESLint config, other view engines' templates, pnpm settings in an npm
|
|
86
|
+
app); they are not removed
|
|
87
|
+
|
|
88
|
+
### Fixed
|
|
89
|
+
|
|
90
|
+
- Error pages show the status code in every environment, not only in development, and have a title
|
|
91
|
+
- `error.ejs` is a full HTML page with the stylesheet, like the other engines' error pages
|
|
92
|
+
- twig layouts escape the page title, which error pages set to the error message
|
|
93
|
+
- Web apps with views no longer show server errors' messages outside development, only
|
|
94
|
+
`Internal Server Error`, as JSON APIs already did
|
|
95
|
+
- `--no-view` apps have their own error handler, responding with plain text and logging only server
|
|
96
|
+
errors, instead of Express's default handler logging the stack of every error, including client
|
|
97
|
+
errors such as invalid JSON
|
|
98
|
+
- twig error pages escape the error message and stack, as twig.js does not escape output by default
|
|
99
|
+
- An overwritten or identical `bin/www` is made executable, as writing an existing file kept its mode
|
|
100
|
+
- A file where the app needs a folder (or a folder where it needs a file) is reported before
|
|
101
|
+
anything is written, instead of failing with a partly generated app
|
|
102
|
+
- The wizard reports a package manager that is not installed once, with where to get it, instead of
|
|
103
|
+
printing the failure and next steps twice
|
|
104
|
+
|
|
105
|
+
### Removed
|
|
106
|
+
|
|
107
|
+
- The dust, hjs (Hogan.js), jade and vash view engines
|
|
108
|
+
- CSS preprocessor support (`--css`); apps use plain CSS
|
|
109
|
+
- The `-e/--ejs`, `--hbs`, `--pug` and `-H/--hogan` aliases; use `--view=<engine>`
|
|
110
|
+
- The `debug` package and `DEBUG=...` start instructions
|
|
111
|
+
|
|
112
|
+
[Unreleased]: https://github.com/w0244079/create-express-new/compare/v1.0.0...HEAD
|
|
113
|
+
[1.0.0]: https://github.com/w0244079/create-express-new/releases/tag/v1.0.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2009-2013 TJ Holowaychuk <tj@vision-media.ca>
|
|
4
|
+
Copyright (c) 2015-2018 Douglas Christopher Wilson <doug@somethingdoug.com>
|
|
5
|
+
Copyright (c) 2026 Michael Caines
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
8
|
+
a copy of this software and associated documentation files (the
|
|
9
|
+
'Software'), to deal in the Software without restriction, including
|
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
12
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
13
|
+
the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be
|
|
16
|
+
included in all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
21
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
22
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
23
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
24
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,282 @@
|
|
|
1
|
-
#
|
|
1
|
+
# create-express-new
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An application generator for [Express 5](https://expressjs.com/), creating web apps or JSON APIs
|
|
4
|
+
as ES modules, TypeScript or CommonJS that run on current Node.js with no build step.
|
|
5
|
+
|
|
6
|
+
[![NPM Version][npm-image]][npm-url]
|
|
7
|
+
[![NPM Downloads][downloads-image]][npm-url]
|
|
8
|
+
[![Node.js Version][node-image]][npm-url]
|
|
9
|
+
[![License][license-image]](LICENSE)
|
|
10
|
+
[![CI][github-actions-ci-image]][github-actions-ci-url]
|
|
11
|
+
[![OpenSSF Scorecard][scorecard-image]][scorecard-url]
|
|
12
|
+
|
|
13
|
+
`create-express-new` is a fork of [`express-generator`](https://github.com/expressjs/generator),
|
|
14
|
+
the original Express application generator, reimagined for today's Express apps. It keeps the
|
|
15
|
+
familiar `express` command and project layout, and updates everything it generates for Express 5
|
|
16
|
+
and modern Node.js. It is not affiliated with or endorsed by the Express project.
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
Run the generator with no arguments to be guided through the options (requires Node.js 22.9 or newer):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
$ pnpm create express-new@latest
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`npm create express-new@latest` starts the same wizard. It asks for:
|
|
27
|
+
|
|
28
|
+
- the project directory (`.` for the current directory)
|
|
29
|
+
- a web app or a JSON API, and the view engine
|
|
30
|
+
- the language: JavaScript, TypeScript or CommonJS
|
|
31
|
+
- optional middleware, and CSRF protection with sessions
|
|
32
|
+
- the request logger
|
|
33
|
+
- extras: a Dockerfile and ESLint
|
|
34
|
+
- a `.gitignore`
|
|
35
|
+
- the [package manager](#package-manager) the app requires: pnpm, or npm
|
|
36
|
+
|
|
37
|
+
Esc (or ←) goes back a question, keeping your answers. At the end the wizard shows the equivalent
|
|
38
|
+
command, to repeat the setup or use in scripts, and offers to install the dependencies.
|
|
39
|
+
|
|
40
|
+
In a directory that already has files:
|
|
41
|
+
|
|
42
|
+
- Files the app would replace are listed, and the wizard asks whether to overwrite them, keep your
|
|
43
|
+
config files (see `--keep-config` below) or cancel.
|
|
44
|
+
- Files with the same contents are left alone.
|
|
45
|
+
- An existing `.gitignore` is never replaced; the lines it is missing are added at the end.
|
|
46
|
+
- A file where the app needs a folder, or a folder where it needs a file, stops anything being written.
|
|
47
|
+
- Files from an earlier app with other options, such as an `app.js` next to a new `app.ts`, are left
|
|
48
|
+
in place and listed in a warning.
|
|
49
|
+
|
|
50
|
+
Or pass the directory and options directly:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
$ pnpm create express-new@latest my-app --ts --helmet
|
|
54
|
+
$ cd my-app
|
|
55
|
+
$ pnpm install
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
With `npm create`, put the options after `--`: `npm create express-new@latest my-app -- --ts --helmet`.
|
|
59
|
+
`npx create-express-new my-app --ts --helmet` needs no `--`. Either way the app requires pnpm unless
|
|
60
|
+
you add `--pm=npm`.
|
|
61
|
+
|
|
62
|
+
Start it at `http://localhost:3000/`, and run its tests, written with the built-in
|
|
63
|
+
[`node:test`](https://nodejs.org/api/test.html) runner:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
$ pnpm dev # restarts on change
|
|
67
|
+
$ pnpm start # without restarting
|
|
68
|
+
$ pnpm test
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
An app generated with `--pm=npm` uses `npm install`, `npm run dev`, `npm start` and `npm test`.
|
|
72
|
+
|
|
73
|
+
You can also install the generator globally, which provides the `express` command:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
$ npm install -g create-express-new
|
|
77
|
+
$ express --view=ejs --helmet my-app
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The original `express-generator` provides an `express` command too, so install only one of them globally.
|
|
81
|
+
|
|
82
|
+
## What You Get
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
my-app
|
|
86
|
+
├── .env.example # example environment variables; copy to .env
|
|
87
|
+
├── .gitignore # ignores node_modules, .env files, logs and coverage
|
|
88
|
+
├── app.js # the Express app: middleware, views, routes, error handling
|
|
89
|
+
├── bin/www.js # starts the server, with graceful shutdown on SIGINT/SIGTERM
|
|
90
|
+
├── package.json # "type": "module", start/dev/test scripts
|
|
91
|
+
├── public/ # static files, including stylesheets/style.css
|
|
92
|
+
├── routes/ # index.js and users.js routers
|
|
93
|
+
├── test/app.test.js # node:test tests for the app
|
|
94
|
+
└── views/ # error, index and layout templates (pug by default)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Every app has a `GET /health` endpoint that responds with `{ "status": "ok" }`, for load balancers,
|
|
98
|
+
container health checks and uptime monitors. It is defined before the middleware, so it stays fast and
|
|
99
|
+
out of the request logs.
|
|
100
|
+
|
|
101
|
+
Server errors (5xx) are logged with `console.error`; client errors (4xx), such as a 404, are not.
|
|
102
|
+
Errors render with the `error` view, or as plain text with `--no-view`. Client errors show their
|
|
103
|
+
message. Server errors only say `Internal Server Error` outside development, so internal details are
|
|
104
|
+
never sent; development shows every error's message and stack.
|
|
105
|
+
|
|
106
|
+
### JSON APIs
|
|
107
|
+
|
|
108
|
+
`--api` generates a JSON API instead of a web app: no views, static files or form parsing, and
|
|
109
|
+
routes that respond with JSON.
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
my-api
|
|
113
|
+
├── app.js # JSON body parsing, routes, JSON 404 and error handling
|
|
114
|
+
├── bin/www.js
|
|
115
|
+
├── package.json
|
|
116
|
+
├── routes/ # index.js and users.js, responding with JSON
|
|
117
|
+
└── test/app.test.js
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Errors are always JSON, such as `{ "error": "Not Found" }`, and follow the same rules as web apps:
|
|
121
|
+
client errors include their message, server errors only say `Internal Server Error` in production,
|
|
122
|
+
and development adds the stack trace. Express runs in development mode unless `NODE_ENV` is set, so
|
|
123
|
+
set `NODE_ENV=production` when you deploy.
|
|
124
|
+
|
|
125
|
+
`--api` works with `--cjs`, `--ts` and the optional middleware, but not with `--view`.
|
|
126
|
+
|
|
127
|
+
### Module formats
|
|
128
|
+
|
|
129
|
+
- **ES modules** (default): `import`/`export`, `import.meta.dirname` and `node:` built-ins.
|
|
130
|
+
- **CommonJS** (`--cjs`): the same app with `require()`/`module.exports`.
|
|
131
|
+
- **TypeScript** (`--ts`): `.ts` files that Node.js 22.18+ runs directly by
|
|
132
|
+
[stripping types](https://nodejs.org/api/typescript.html#type-stripping), so there is no build step.
|
|
133
|
+
Includes a strict `tsconfig.json`, the `@types` packages the app needs and a `typecheck`
|
|
134
|
+
script that runs `tsc`. `--ts` cannot be combined with `--cjs`.
|
|
135
|
+
|
|
136
|
+
### Configuration
|
|
137
|
+
|
|
138
|
+
The `start` and `dev` scripts load environment variables from a `.env` file when one exists, using
|
|
139
|
+
Node.js's built-in [`--env-file-if-exists`](https://nodejs.org/api/cli.html#--env-file-if-existsfile),
|
|
140
|
+
so no `dotenv` package is needed. Start from the generated example:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
$ cp .env.example .env
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Variables already set in the environment take precedence over `.env`, so your hosting platform's
|
|
147
|
+
settings always win. The `dev` script restarts when `.env` changes. The generated `.gitignore` keeps
|
|
148
|
+
`.env`, and every other `.env.*` file except `.env.example`, out of version control.
|
|
149
|
+
|
|
150
|
+
### Optional middleware
|
|
151
|
+
|
|
152
|
+
By default, generated apps include only request logging, body parsing and static files (no static
|
|
153
|
+
files with `--api`). Add more with:
|
|
154
|
+
|
|
155
|
+
- `--helmet`: [helmet](https://helmetjs.github.io/) security headers
|
|
156
|
+
- `--compression`: gzip/brotli response [compression](https://github.com/expressjs/compression)
|
|
157
|
+
- `--cookies`: [cookie-parser](https://github.com/expressjs/cookie-parser), for reading `req.cookies`
|
|
158
|
+
- `--cors`: [cors](https://github.com/expressjs/cors), allowing requests from other origins
|
|
159
|
+
- `--rate-limit`: [express-rate-limit](https://express-rate-limit.mintlify.app/), limiting each client
|
|
160
|
+
to 100 requests every 15 minutes
|
|
161
|
+
- `--session` (web apps only): [express-session](https://github.com/expressjs/session), for `req.session`
|
|
162
|
+
- `--csrf` (with `--session` and a view engine): [csrf-sync](https://github.com/Psifi-Solutions/csrf-sync)
|
|
163
|
+
CSRF protection for forms
|
|
164
|
+
- `--uploads`: [multer](https://github.com/expressjs/multer) and a `POST /uploads` route that takes one
|
|
165
|
+
file of up to 5 MB
|
|
166
|
+
|
|
167
|
+
[Optional middleware](docs/middleware.md) covers each one's settings and environment variables,
|
|
168
|
+
sending the CSRF token from forms and JavaScript, running behind a proxy, and how
|
|
169
|
+
[uploaded files](docs/middleware.md#file-uploads) are stored and checked.
|
|
170
|
+
|
|
171
|
+
### Request logging
|
|
172
|
+
|
|
173
|
+
Requests are logged with [morgan](https://github.com/expressjs/morgan) by default, one readable line
|
|
174
|
+
per request. `--logger=pino` uses [pino-http](https://github.com/pinojs/pino-http) instead, which logs
|
|
175
|
+
JSON for log collectors and adds `req.log` for your own logs. The `dev` script pipes them through
|
|
176
|
+
[pino-pretty](https://github.com/pinojs/pino-pretty) to keep them readable. Either way, requests are
|
|
177
|
+
not logged while the tests run.
|
|
178
|
+
|
|
179
|
+
### Package manager
|
|
180
|
+
|
|
181
|
+
Every app requires one package manager, pnpm by default or npm with `--pm=npm`, so other package
|
|
182
|
+
managers refuse to install the app or run its scripts. It also has settings that protect installs
|
|
183
|
+
from compromised packages: new releases wait 3 days before they are installed, and the install
|
|
184
|
+
scripts of dependencies are not run. An npm app needs npm 12 or newer, which does not come with
|
|
185
|
+
Node.js 22 or 24.
|
|
186
|
+
|
|
187
|
+
[Package manager](docs/package-manager.md) compares the pnpm and npm settings, and covers allowing
|
|
188
|
+
a dependency's install script, installing a release sooner and changing package manager later.
|
|
189
|
+
|
|
190
|
+
### Docker
|
|
191
|
+
|
|
192
|
+
`--docker` adds a `Dockerfile` and `.dockerignore` for a production image. Install dependencies
|
|
193
|
+
first, as the image installs from the lockfile:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
$ pnpm install
|
|
197
|
+
$ docker build -t my-app .
|
|
198
|
+
$ docker run -p 3000:3000 my-app
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
The image:
|
|
202
|
+
|
|
203
|
+
- is based on `node:22-slim`, the latest release of the minimum supported Node.js version
|
|
204
|
+
- installs only production dependencies, in a build stage of their own, so the package manager is
|
|
205
|
+
not in the final image
|
|
206
|
+
- runs the app as the unprivileged `node` user with `NODE_ENV=production`
|
|
207
|
+
- checks `/health` with a `HEALTHCHECK`
|
|
208
|
+
- runs `node` directly, so it receives `SIGTERM` and shuts down gracefully
|
|
209
|
+
- does not copy `.env` files; set environment variables with your container platform instead. With
|
|
210
|
+
`--session`, the app needs `SESSION_SECRET` to start, such as
|
|
211
|
+
`docker run -e SESSION_SECRET=... -p 3000:3000 my-app`
|
|
212
|
+
|
|
213
|
+
### Linting
|
|
214
|
+
|
|
215
|
+
`--lint` adds [ESLint](https://eslint.org/) with its recommended rules and a `lint` script. With
|
|
216
|
+
`--ts` it also adds [typescript-eslint](https://typescript-eslint.io/); as typescript-eslint does not
|
|
217
|
+
support TypeScript 7 yet, these apps use TypeScript 6.
|
|
218
|
+
|
|
219
|
+
## Command Line Options
|
|
220
|
+
|
|
221
|
+
-v, --view <engine> add view <engine> support (ejs|hbs|pug|twig) (defaults to pug)
|
|
222
|
+
--no-view use static html instead of view engine
|
|
223
|
+
--api generate a JSON API, without views or static files
|
|
224
|
+
--cjs generate CommonJS modules instead of ES modules
|
|
225
|
+
--ts generate TypeScript, run directly by Node.js
|
|
226
|
+
--helmet add helmet middleware for security headers
|
|
227
|
+
--compression add compression middleware for gzip/brotli responses
|
|
228
|
+
--cookies add cookie-parser middleware
|
|
229
|
+
--cors add cors middleware for cross-origin requests
|
|
230
|
+
--rate-limit add express-rate-limit to limit requests per client
|
|
231
|
+
--session add express-session for sessions (not with --api)
|
|
232
|
+
--csrf add CSRF protection for forms (needs --session)
|
|
233
|
+
--uploads add multer and an upload route at /uploads
|
|
234
|
+
--logger <name> request logger (morgan|pino) (defaults to morgan)
|
|
235
|
+
--docker add a Dockerfile for a production image
|
|
236
|
+
--lint add ESLint and a lint script
|
|
237
|
+
--pm <name> package manager the app requires (pnpm|npm) (defaults to pnpm)
|
|
238
|
+
--no-git skip the .gitignore
|
|
239
|
+
-f, --force force on non-empty directory
|
|
240
|
+
--keep-config keep existing config files (.env.example, Dockerfile,
|
|
241
|
+
.dockerignore, tsconfig.json, eslint.config.*,
|
|
242
|
+
pnpm-workspace.yaml, .npmrc)
|
|
243
|
+
--version output the version number
|
|
244
|
+
-h, --help output usage information
|
|
245
|
+
|
|
246
|
+
## Changes From express-generator
|
|
247
|
+
|
|
248
|
+
This fork started from `express-generator` 4.16.1. It generates Express 5 apps as ES modules, with
|
|
249
|
+
pug in place of jade, for Node.js 22.9 or newer. `--view=<engine>` replaces the `--ejs`, `--hbs` and
|
|
250
|
+
`--pug` aliases, and apps use plain CSS instead of a CSS preprocessor.
|
|
251
|
+
|
|
252
|
+
- [Changes from express-generator](docs/changes-from-express-generator.md): everything added,
|
|
253
|
+
changed and removed, and a table for migrating commands
|
|
254
|
+
- [Using Sass](docs/sass.md): adding Sass to a generated app
|
|
255
|
+
|
|
256
|
+
## Contributing
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
$ npm install
|
|
260
|
+
$ npm test # generates, installs and runs apps for each option
|
|
261
|
+
$ npm run lint
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
The tests install the generated apps with pnpm, so [install pnpm](https://pnpm.io/installation)
|
|
265
|
+
first. The tests that install an npm app are skipped unless your npm is version 12 or newer.
|
|
266
|
+
|
|
267
|
+
See [Maintaining](docs/maintaining.md) for keeping the dependency versions of generated apps current,
|
|
268
|
+
and for releasing.
|
|
269
|
+
|
|
270
|
+
## License
|
|
271
|
+
|
|
272
|
+
[MIT](LICENSE). Originally created by TJ Holowaychuk and the Express contributors.
|
|
273
|
+
|
|
274
|
+
[npm-image]: https://img.shields.io/npm/v/create-express-new.svg
|
|
275
|
+
[npm-url]: https://www.npmjs.com/package/create-express-new
|
|
276
|
+
[downloads-image]: https://img.shields.io/npm/dm/create-express-new.svg
|
|
277
|
+
[node-image]: https://img.shields.io/node/v/create-express-new.svg
|
|
278
|
+
[license-image]: https://img.shields.io/npm/l/create-express-new.svg
|
|
279
|
+
[github-actions-ci-image]: https://github.com/w0244079/create-express-new/actions/workflows/ci.yml/badge.svg
|
|
280
|
+
[github-actions-ci-url]: https://github.com/w0244079/create-express-new/actions/workflows/ci.yml
|
|
281
|
+
[scorecard-image]: https://api.scorecard.dev/projects/github.com/w0244079/create-express-new/badge
|
|
282
|
+
[scorecard-url]: https://scorecard.dev/viewer/?uri=github.com/w0244079/create-express-new
|