Skip to content

Commit ca56838

Browse files
authored
Merge branch 'master' into docs/update-migration-page
2 parents d66afc2 + 331ed6a commit ca56838

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+3806
-17476
lines changed

.github/workflows/lighthouse.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111

1212
steps:
1313
- uses: actions/checkout@v3
14-
- name: Use Node.js 12.x
14+
- name: Use Node.js 16.x
1515
uses: actions/setup-node@v3
1616
with:
17-
node-version: 12.x
17+
node-version: 16.x
1818
# Build needs around 400 seconds on Netlify.
1919
# We can not rely on "Waiting for 200", since the user
2020
# might push another commit to an existing PR, meaning

angular.json

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
"src/_redirects"
2828
],
2929
"styles": [
30-
"src/styles.scss",
31-
"src/assets/css/perfect-scrollbar.min.css"
30+
"src/styles.scss"
3231
]
3332
},
3433
"configurations": {
@@ -110,31 +109,6 @@
110109
}
111110
}
112111
}
113-
},
114-
"docs.nestjs.com-e2e": {
115-
"root": "e2e",
116-
"sourceRoot": "e2e",
117-
"projectType": "application",
118-
"architect": {
119-
"e2e": {
120-
"builder": "@angular-devkit/build-angular:protractor",
121-
"options": {
122-
"protractorConfig": "./protractor.conf.js",
123-
"devServerTarget": "docs.nestjs.com:serve"
124-
}
125-
},
126-
"lint": {
127-
"builder": "@angular-devkit/build-angular:tslint",
128-
"options": {
129-
"tsConfig": [
130-
"e2e/tsconfig.e2e.json"
131-
],
132-
"exclude": [
133-
"**/node_modules/**"
134-
]
135-
}
136-
}
137-
}
138112
}
139113
},
140114
"defaultProject": "docs.nestjs.com",

content/cli/workspaces.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ These properties specify the compiler to use as well as various options that aff
192192
| `assets` | array | Enables automatically distributing non-TypeScript assets whenever a compilation step begins (asset distribution does **not** happen on incremental compiles in `--watch` mode). See below for details. |
193193
| `watchAssets` | boolean | If `true`, run in watch-mode, watching **all** non-TypeScript assets. (For more fine-grained control of the assets to watch, see [Assets](cli/monorepo#assets) section below). |
194194
| `manualRestart` | boolean | If `true`, enables the shortcut `rs` to manually restart the server. Default value is `false`. |
195-
| `builder` | string | Instructs CLI on what `builder` to use to compile the project (`tsc`, `swc`, or `webpack`) |
195+
| `builder` | string/object | Instructs CLI on what `builder` to use to compile the project (`tsc`, `swc`, or `webpack`). To customize builder's behavior, you can pass an object containing two attributes: `type` (`tsc`, `swc`, or `webpack`) and `options`. |
196196
| `typeCheck` | boolean | If `true`, enables type checking for SWC-driven projects (when `builder` is `swc`). Default value is `false`. |
197197

198198
#### Global generate options

content/controllers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ findAll() {
202202

203203
The `'ab*cd'` route path will match `abcd`, `ab_cd`, `abecd`, and so on. The characters `?`, `+`, `*`, and `()` may be used in a route path, and are subsets of their regular expression counterparts. The hyphen ( `-`) and the dot (`.`) are interpreted literally by string-based paths.
204204

205+
> warning **Warning** A wildcard in the middle of the route is only supported by express.
206+
205207
#### Status code
206208

207209
As mentioned, the response **status code** is always **200** by default, except for POST requests which are **201**. We can easily change this behavior by adding the `@HttpCode(...)` decorator at a handler level.
@@ -510,8 +512,6 @@ export class AppModule {}
510512

511513
We attached the metadata to the module class using the `@Module()` decorator, and Nest can now easily reflect which controllers have to be mounted.
512514

513-
<app-banner-shop></app-banner-shop>
514-
515515
#### Library-specific approach
516516

517517
So far we've discussed the Nest standard way of manipulating responses. The second way of manipulating the response is to use a library-specific [response object](https://expressjs.com/en/api.html#res). In order to inject a particular response object, we need to use the `@Res()` decorator. To show the differences, let's rewrite the `CatsController` to the following:

content/devtools/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ fs.writeFileSync('./graph.json', app.get(SerializedGraph).toString());
191191

192192
> info **Hint** `SerializedGraph` is exported from the `@nestjs/core` package.
193193
194-
Then you can drag and drop this/upload this file:
194+
Then you can drag and drop/upload this file:
195195

196196
<figure><img src="/assets/devtools/drag-and-drop.png" /></figure>
197197

content/discover/who-uses.json

Lines changed: 27 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -36,169 +36,57 @@
3636
"url": "https://www.neo4j.com/"
3737
},
3838
{
39-
"logo": "/assets/logo/shipt.png",
40-
"url": "https://www.shipt.com/"
41-
},
42-
{
43-
"logo": "/assets/logo/sanofi.png",
44-
"url": "https://github.com/Sanofi-IADC"
45-
},
46-
{
47-
"logo": "https://nestjs.com/img/valor-software.png",
48-
"url": "https://valor-software.com/"
49-
},
50-
{
51-
"logo": "/assets/logo/sitepen.svg",
52-
"url": "https://sitepen.com"
53-
},
54-
{
55-
"logo": "https://nestjs.com/img/gojob-logo.png",
56-
"url": "https://gojob.com/",
57-
"width": "100px"
58-
},
59-
{
60-
"logo": "https://nestjs.com/img/neoteric.png",
61-
"url": "https://neoteric.eu/"
62-
},
63-
{
64-
"logo": "/assets/logo/trellis.png",
65-
"url": "https://trellis.org/",
66-
"width": "70px"
39+
"logo": "/assets/logo/bmw.svg",
40+
"url": "https://bmw.com"
6741
},
6842
{
69-
"logo": "https://nestjs.com/img/scalio-logo.svg",
70-
"url": "https://scal.io",
71-
"width": "120px"
72-
},
73-
{
74-
"logo": "https://nestjs.com/img/swingdev-logo.svg",
75-
"url": "https://swingdev.io/"
76-
},
77-
{
78-
"logo": "/assets/logo/cultura-colectiva.png",
79-
"url": "https://culturacolectiva.com",
80-
"width": "90px"
81-
},
82-
{
83-
"logo": "https://nestjs.com/img/trilon.png",
84-
"url": "https://trilon.io"
43+
"logo": "/assets/logo/gitlab.png",
44+
"url": "https://gitlab.com/"
8545
},
8646
{
87-
"logo": "/assets/logo/architectnow.png",
88-
"url": "http://architectnow.net",
89-
"width": "150px"
47+
"logo": "/assets/logo/ibm.svg",
48+
"url": "https://www.ibm.com/"
9049
},
9150
{
92-
"logo": "/assets/logo/iflix.svg",
93-
"url": "https://www.iflix.com",
94-
"width": "70px"
51+
"logo": "/assets/logo/jetbrains.svg",
52+
"url": "https://www.jetbrains.com/"
9553
},
9654
{
97-
"logo": "https://nestjs.com/img/genuinebee.svg",
98-
"url": "https://genuinebee.com/"
55+
"logo": "/assets/logo/mercedes.png",
56+
"url": "https://www.mercedes-benz.com/"
9957
},
10058
{
101-
"logo": "/assets/logo/run-players-league.png",
102-
"url": "https://runplayersleague.com",
103-
"width": "80px"
59+
"logo": "/assets/logo/totalenergies.svg",
60+
"url": "https://totalenergies.com/"
10461
},
10562
{
106-
"logo": "/assets/logo/yanrongyun.svg",
107-
"url": "http://www.yanrongyun.com",
108-
"width": "120px"
63+
"logo": "/assets/logo/bytedance.png",
64+
"url": "https://www.bytedance.com"
10965
},
11066
{
111-
"logo": "/assets/logo/sclable.svg",
112-
"url": "https://sclable.com",
113-
"width": "120px"
114-
},
115-
{
116-
"logo": "/assets/logo/dozto.png",
117-
"url": "https://www.dozto.com",
118-
"width": "117px"
119-
},
120-
{
121-
"logo": "/assets/logo/qingtui.png",
122-
"url": "https://www.qingtui.cn/",
123-
"width": "90px"
67+
"logo": "/assets/logo/ibm.svg",
68+
"url": "https://www.ibm.com/"
12469
},
12570
{
126-
"logo": "/assets/logo/crowdlinker.svg",
127-
"url": "https://crowdlinker.com/",
128-
"width": "110px"
129-
},
130-
{
131-
"logo": "/assets/logo/nothing.svg",
132-
"url": "https://nothing.ch/",
133-
"width": "110px"
134-
},
135-
{
136-
"logo": "/assets/logo/swissdevjobs-devops-logo.png",
137-
"url": "https://swissdevjobs.ch/jobs/Dev-Ops/All",
138-
"width": "65px"
139-
},
140-
{
141-
"logo": "/assets/logo/zeoagency.svg",
142-
"url": "https://zeo.org/tr/",
143-
"width": "80px"
144-
},
145-
{
146-
"logo": "/assets/logo/valueadd.png",
147-
"url": "https://valueadd.pl/",
148-
"width": "120px"
149-
},
150-
{
151-
"logo": "/assets/logo/bedu.svg",
152-
"url": "https://bedu.org",
153-
"width": "100px"
154-
},
155-
{
156-
"logo": "/assets/logo/shopback.png",
157-
"url": "https://shopback.com",
158-
"width": "100px"
159-
},
160-
{
161-
"logo": "/assets/logo/facile.png",
162-
"url": "https://www.facile.it",
163-
"width": "100px"
164-
},
165-
{
166-
"logo": "/assets/logo/interfacewerk.png",
167-
"url": "https://interfacewerk.de",
168-
"width": "130px"
169-
},
170-
{
171-
"logo": "/assets/logo/ottonova.png",
172-
"url": "https://www.ottonova.de",
173-
"width": "130px"
71+
"logo": "/assets/logo/shipt.png",
72+
"url": "https://www.shipt.com/"
17473
},
17574
{
176-
"logo": "/assets/logo/radity.png",
177-
"url": "https://radity.com",
178-
"width": "120px"
75+
"logo": "/assets/logo/sanofi.png",
76+
"url": "https://github.com/Sanofi-IADC"
17977
},
18078
{
181-
"logo": "/assets/logo/global-cto-forum.png",
182-
"url": "https://globalctoforum.org/",
183-
"width": "120px"
79+
"logo": "/assets/logo/sitepen.svg",
80+
"url": "https://sitepen.com"
18481
},
18582
{
186-
"logo": "/assets/logo/rivvy.png",
187-
"url": "https://rivvy.app",
188-
"width": "120px"
83+
"logo": "https://nestjs.com/img/trilon.png",
84+
"url": "https://trilon.io"
18985
},
19086
{
19187
"logo": "/assets/logo/vue-storefront.png",
19288
"url": "https://www.vuestorefront.io/"
19389
},
194-
{
195-
"logo": "/assets/logo/fuse-logo.svg",
196-
"url": "https://fuseautotech.com"
197-
},
198-
{
199-
"logo": "/assets/logo/amplication.svg",
200-
"url": "https://amplication.com"
201-
},
20290
{
20391
"logo": "/assets/logo/hingehealth.png",
20492
"url": "https://hingehealth.com",
@@ -280,6 +168,8 @@
280168
"https://tarken.com.br",
281169
"https://remato.com",
282170
"https://remberg.de/en",
283-
"https://uninterrupted.tech"
171+
"https://uninterrupted.tech",
172+
"https://www.digando.com",
173+
"https://novu.co"
284174
]
285175
}

content/exception-filters.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ async create(createCatDto) {
260260

261261
> info **Hint** Prefer applying filters by using classes instead of instances when possible. It reduces **memory usage** since Nest can easily reuse instances of the same class across your entire module.
262262
263-
In the example above, the `HttpExceptionFilter` is applied only to the single `create()` route handler, making it method-scoped. Exception filters can be scoped at different levels: method-scoped, controller-scoped, or global-scoped. For example, to set up a filter as controller-scoped, you would do the following:
263+
In the example above, the `HttpExceptionFilter` is applied only to the single `create()` route handler, making it method-scoped. Exception filters can be scoped at different levels: method-scoped of the controller/resolver/gateway, controller-scoped, or global-scoped.
264+
For example, to set up a filter as controller-scoped, you would do the following:
264265

265266
```typescript
266267
@@filename(cats.controller)

content/faq/multiple-servers.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,41 @@ const app = await NestFactory.create(
3939
);
4040
await app.init();
4141

42-
http.createServer(server).listen(3000);
43-
https.createServer(httpsOptions, server).listen(443);
42+
const httpServer = http.createServer(server).listen(3000);
43+
const httpsServer = https.createServer(httpsOptions, server).listen(443);
44+
```
45+
46+
Because we called `http.createServer` / `https.createServer` ourselves, NestJS doesn't close them when calling `app.close` / on termination signal. We need to do this ourselves:
47+
48+
```typescript
49+
@Injectable()
50+
export class ShutdownObserver implements OnApplicationShutdown {
51+
private httpServers: http.Server[] = [];
52+
53+
public addHttpServer(server: http.Server): void {
54+
this.httpServers.push(server);
55+
}
56+
57+
public async onApplicationShutdown(): Promise<void> {
58+
await Promise.all(
59+
this.httpServers.map((server) =>
60+
new Promise((resolve, reject) => {
61+
server.close((error) => {
62+
if (error) {
63+
reject(error);
64+
} else {
65+
resolve(null);
66+
}
67+
});
68+
})
69+
),
70+
);
71+
}
72+
}
73+
74+
const shutdownObserver = app.get(ShutdownObserver);
75+
shutdownObserver.addHttpServer(httpServer);
76+
shutdownObserver.addHttpServer(httpsServer);
4477
```
4578

4679
> info **Hint** The `ExpressAdapter` is imported from the `@nestjs/platform-express` package. The `http` and `https` packages are native Node.js packages.

content/first-steps.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,21 @@ $ npm run start:dev
114114
```
115115

116116
This command will watch your files, automatically recompiling and reloading the server.
117+
118+
#### Linting and formatting
119+
120+
[CLI](/cli/overview) provides best effort to scaffold a reliable development workflow at scale. Thus, a generated Nest project comes with both a code **linter** and **formatter** preinstalled (respectively [eslint](https://eslint.org/) and [prettier](https://prettier.io/)).
121+
122+
> info **Hint** Not sure about the role of formatters vs linters? Learn the difference [here](https://prettier.io/docs/en/comparison.html).
123+
124+
To ensure maximum stability and extensibility, we use the base [`eslint`](https://www.npmjs.com/package/eslint) and [`prettier`](https://www.npmjs.com/package/prettier) cli packages. This setup allows neat IDE integration with official extensions by design.
125+
126+
For headless environments where an IDE is not relevant (Continuous Integration, Git hooks, etc.) a Nest project comes with ready-to-use `npm` scripts.
127+
128+
```bash
129+
# Lint and autofix with eslint
130+
$ npm run lint
131+
132+
# Format with prettier
133+
$ npm run format
134+
```

0 commit comments

Comments
 (0)