Skip to content

Commit 56fd4a2

Browse files
docs: update listen to use port env variable
1 parent 3b7cc15 commit 56fd4a2

21 files changed

+68
-70
lines changed

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"singleQuote": true,
3-
"trailingComma": "all"
3+
"trailingComma": "all",
4+
"printWidth": 80
45
}

content/devtools/ci-cd.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function bootstrap() {
4040

4141
await app.close();
4242
} else {
43-
await app.listen(3000);
43+
await app.listen(process.env.PORT ?? 3000);
4444
}
4545
}
4646
```
@@ -232,9 +232,7 @@ const publishOptions = {
232232
sha: process.env.CI_COMMIT_SHA,
233233
target: process.env.CI_MERGE_REQUEST_DIFF_BASE_SHA,
234234
trigger: process.env.CI_MERGE_REQUEST_DIFF_BASE_SHA ? 'pull' : 'push',
235-
branch:
236-
process.env.CI_COMMIT_BRANCH ??
237-
process.env.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME,
235+
branch: process.env.CI_COMMIT_BRANCH ?? process.env.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME,
238236
};
239237
```
240238

content/devtools/overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async function bootstrap() {
99
const app = await NestFactory.create(AppModule, {
1010
snapshot: true,
1111
});
12-
await app.listen(3000);
12+
await app.listen(process.env.PORT ?? 3000);
1313
}
1414
```
1515

@@ -185,7 +185,7 @@ This page comes in handy when you want to identify potential issues in your appl
185185
To save a serialized graph to a file, use the following code:
186186

187187
```typescript
188-
await app.listen(3000); // OR await app.init()
188+
await app.listen(process.env.PORT ?? 3000); // OR await app.init()
189189
fs.writeFileSync('./graph.json', app.get(SerializedGraph).toString());
190190
```
191191

content/exception-filters.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ Nest provides a set of standard exceptions that inherit from the base `HttpExcep
141141
All the built-in exceptions can also provide both an error `cause` and an error description using the `options` parameter:
142142

143143
```typescript
144-
throw new BadRequestException('Something bad happened', { cause: new Error(), description: 'Some error description' })
144+
throw new BadRequestException('Something bad happened', {
145+
cause: new Error(),
146+
description: 'Some error description',
147+
});
145148
```
146149

147150
Using the above, this is how the response would look:
@@ -150,7 +153,7 @@ Using the above, this is how the response would look:
150153
{
151154
"message": "Something bad happened",
152155
"error": "Some error description",
153-
"statusCode": 400,
156+
"statusCode": 400
154157
}
155158
```
156159

@@ -278,7 +281,7 @@ To create a global-scoped filter, you would do the following:
278281
async function bootstrap() {
279282
const app = await NestFactory.create(AppModule);
280283
app.useGlobalFilters(new HttpExceptionFilter());
281-
await app.listen(3000);
284+
await app.listen(process.env.PORT ?? 3000);
282285
}
283286
bootstrap();
284287
```
@@ -394,7 +397,7 @@ async function bootstrap() {
394397
const { httpAdapter } = app.get(HttpAdapterHost);
395398
app.useGlobalFilters(new AllExceptionsFilter(httpAdapter));
396399

397-
await app.listen(3000);
400+
await app.listen(process.env.PORT ?? 3000);
398401
}
399402
bootstrap();
400403
```

content/faq/keep-alive-connections.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function bootstrap() {
1818
const app = await NestFactory.create(AppModule, {
1919
forceCloseConnections: true,
2020
});
21-
await app.listen(3000);
21+
await app.listen(process.env.PORT ?? 3000);
2222
}
2323

2424
bootstrap();

content/faq/multiple-servers.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const httpsOptions = {
1010
const app = await NestFactory.create(AppModule, {
1111
httpsOptions,
1212
});
13-
await app.listen(3000);
13+
await app.listen(process.env.PORT ?? 3000);
1414
```
1515

1616
If you use the `FastifyAdapter`, create the application as follows:
@@ -33,10 +33,7 @@ const httpsOptions = {
3333
};
3434

3535
const server = express();
36-
const app = await NestFactory.create(
37-
AppModule,
38-
new ExpressAdapter(server),
39-
);
36+
const app = await NestFactory.create(AppModule, new ExpressAdapter(server));
4037
await app.init();
4138

4239
const httpServer = http.createServer(server).listen(3000);
@@ -56,16 +53,17 @@ export class ShutdownObserver implements OnApplicationShutdown {
5653

5754
public async onApplicationShutdown(): Promise<void> {
5855
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-
})
56+
this.httpServers.map(
57+
(server) =>
58+
new Promise((resolve, reject) => {
59+
server.close((error) => {
60+
if (error) {
61+
reject(error);
62+
} else {
63+
resolve(null);
64+
}
65+
});
66+
}),
6967
),
7068
);
7169
}

content/faq/raw-body.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { AppModule } from './app.module';
1717
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
1818
rawBody: true,
1919
});
20-
await app.listen(3000);
20+
await app.listen(process.env.PORT ?? 3000);
2121
```
2222

2323
To access the raw request body in a controller, a convenience interface `RawBodyRequest` is provided to expose a `rawBody` field on the request: use the interface `RawBodyRequest` type:
@@ -77,7 +77,7 @@ const app = await NestFactory.create<NestFastifyApplication>(
7777
rawBody: true,
7878
},
7979
);
80-
await app.listen(3000);
80+
await app.listen(process.env.PORT ?? 3000);
8181
```
8282

8383
To access the raw request body in a controller, a convenience interface `RawBodyRequest` is provided to expose a `rawBody` field on the request: use the interface `RawBodyRequest` type:

content/faq/serverless.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { AppModule } from './app.module';
3737

3838
async function bootstrap() {
3939
const app = await NestFactory.create(AppModule, { logger: ['error'] });
40-
await app.listen(3000);
40+
await app.listen(process.env.PORT ?? 3000);
4141
}
4242
bootstrap();
4343

content/first-steps.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import { AppModule } from './app.module';
5656

5757
async function bootstrap() {
5858
const app = await NestFactory.create(AppModule);
59-
await app.listen(3000);
59+
await app.listen(process.env.PORT ?? 3000);
6060
}
6161
bootstrap();
6262
@@switch
@@ -65,7 +65,7 @@ import { AppModule } from './app.module';
6565

6666
async function bootstrap() {
6767
const app = await NestFactory.create(AppModule);
68-
await app.listen(3000);
68+
await app.listen(process.env.PORT ?? 3000);
6969
}
7070
bootstrap();
7171
```

content/fundamentals/lifecycle-events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async function bootstrap() {
8484
// Starts listening for shutdown hooks
8585
app.enableShutdownHooks();
8686

87-
await app.listen(3000);
87+
await app.listen(process.env.PORT ?? 3000);
8888
}
8989
bootstrap();
9090
```

0 commit comments

Comments
 (0)