Skip to content

Commit 2041509

Browse files
2 parents 5420dd2 + 92a0394 commit 2041509

File tree

13 files changed

+221
-82
lines changed

13 files changed

+221
-82
lines changed

content/devtools/overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ First, open up the `main.ts` file and update the `bootstrap()` call, as follows:
7070

7171
```typescript
7272
bootstrap().catch((err) => {
73-
writeFileSync('graph.json', PartialGraphHost.toString() ?? '');
73+
fs.writeFileSync('graph.json', PartialGraphHost.toString() ?? '');
7474
process.exit(1);
7575
});
7676
```
@@ -130,7 +130,7 @@ To save a serialized graph to a file, use the following code:
130130

131131
```typescript
132132
await app.listen(3000); // OR await app.init()
133-
writeFileSync('./graph.json', app.get(SerializedGraph).toString());
133+
fs.writeFileSync('./graph.json', app.get(SerializedGraph).toString());
134134
```
135135

136136
> info **Hint** `SerializedGraph` is exported from the `@nestjs/core` package.

content/faq/errors.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ During your development with NestJS, you may encounter various errors as you lea
44

55
#### "Cannot resolve dependency" error
66

7+
> info **Hint** Check out the [NestJS Devtools](/devtools/overview#investigating-the-cannot-resolve-dependency-error) which can help you resolve the "Cannot resolve dependency" error effortlessly.
8+
79
Probably the most common error message is about Nest not being able to resolve dependencies of a provider. The error message usually looks something like this:
810

911
```bash
@@ -20,8 +22,6 @@ Potential solutions:
2022
2123
The most common culprit of the error, is not having the `<provider>` in the module's `providers` array. Please make sure that the provider is indeed in the `providers` array and following [standard NestJS provider practices](/fundamentals/custom-providers#di-fundamentals).
2224

23-
<app-banner-devtools></app-banner-devtools>
24-
2525
There are a few gotchas, that are common. One is putting a provider in an `imports` array. If this is the case, the error will have the provider's name where `<module>` should be.
2626
2727
If you run across this error while developing, take a look at the module mentioned in the error message and look at its `providers`. For each provider in the `providers` array, make sure the module has access to all of the dependencies. Often times, `providers` are duplicated in a "Feature Module" and a "Root Module" which means Nest will try to instantiate the provider twice. More than likely, the module containing the `<provider>` being duplicated should be added in the "Root Module"'s `imports` array instead.
@@ -32,6 +32,8 @@ If the `<unknown_token>` above is the string `Object`, it means that you're inje
3232
3333
Also, make sure you didn't end up injecting the provider on itself because self-injections are not allowed in NestJS. When this happens, `<unknown_token>` will likely be equal to `<provider>`.
3434

35+
<app-banner-devtools></app-banner-devtools>
36+
3537
If you are in a **monorepo setup**, you may face the same error as above but for core provider called `ModuleRef` as a `<unknown_token>`:
3638

3739
```bash

content/faq/global-prefix.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ Alternatively, you can specify route as a string (it will apply to every request
2020
```typescript
2121
app.setGlobalPrefix('v1', { exclude: ['cats'] });
2222
```
23+
24+
> info **Hint** The `path` property supports wildcard parameters using the [path-to-regexp](https://github.com/pillarjs/path-to-regexp#parameters) package. Note: this does not accept wildcard asterisks `*`. Instead, you must use parameters (e.g., `(.*)`, `:splat*`).

content/faq/hybrid-application.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A hybrid application is one that both listens for HTTP requests, as well as make
44

55
```typescript
66
const app = await NestFactory.create(AppModule);
7-
const microservice = app.connectMicroservice({
7+
const microservice = app.connectMicroservice<MicroserviceOptions>({
88
transport: Transport.TCP,
99
});
1010

@@ -71,7 +71,7 @@ By default a hybrid application will not inherit global pipes, interceptors, gua
7171
To inherit these configuration properties from the main application, set the `inheritAppConfig` property in the second argument (an optional options object) of the `connectMicroservice()` call, as follow:
7272

7373
```typescript
74-
const microservice = app.connectMicroservice(
74+
const microservice = app.connectMicroservice<MicroserviceOptions>(
7575
{
7676
transport: Transport.TCP,
7777
},

content/microservices/basics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async function bootstrap() {
3838
bootstrap();
3939
@@switch
4040
import { NestFactory } from '@nestjs/core';
41-
import { Transport, MicroserviceOptions } from '@nestjs/microservices';
41+
import { Transport } from '@nestjs/microservices';
4242
import { AppModule } from './app.module';
4343

4444
async function bootstrap() {

content/microservices/kafka.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ The Kafka microservice components append a description of their respective role
371371

372372
```typescript
373373
@@filename(main)
374-
const app = await NestFactory.createMicroservice(AppModule, {
374+
const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
375375
transport: Transport.KAFKA,
376376
options: {
377377
client: {

content/microservices/nats.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ NATS provides a built-in load balancing feature called [distributed queues](http
7777

7878
```typescript
7979
@@filename(main)
80-
const app = await NestFactory.createMicroservice(AppModule, {
80+
const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
8181
transport: Transport.NATS,
8282
options: {
8383
servers: ['nats://localhost:4222'],

content/recipes/automock.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ describe('CatsService unit spec', () => {
7171
beforeAll(() => {
7272
const { unit, unitRef } = TestBed.create(CatsService)
7373
.mock(HttpService)
74+
.use({ get: jest.fn() })
75+
.mock(Logger)
76+
.use({ log: jest.fn() })
77+
.mock(CatsDal)
78+
.use({ saveCats: jest.fn() })
7479
.compile();
7580

7681
underTest = unit;
@@ -82,7 +87,7 @@ describe('CatsService unit spec', () => {
8287

8388
describe('when getting all the cats', () => {
8489
test('then meet some expectations', async () => {
85-
httpService.mockResolvedValueOnce([{ id: 1, name: 'Catty' }]);
90+
httpService.get.mockResolvedValueOnce([{ id: 1, name: 'Catty' }]);
8691
await catsService.getAllCats();
8792

8893
expect(logger.log).toBeCalled();

content/techniques/queues.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ You can designate that a job handler method will handle **only** jobs of a certa
241241
async transcode(job: Job<unknown>) { ... }
242242
```
243243

244+
> warning **Warning** When defining multiple consumers for the same queue, the `concurrency` option in `@Process({ concurrency: 1 })` won't take effect. The minimum `concurrency` will match the number of consumers defined. This also applies even if `@Process()` handlers use a different `name` to handle named jobs.
245+
244246
#### Request-scoped consumers
245247

246248
When a consumer is flagged as request-scoped (learn more about the injection scopes [here](/fundamentals/injection-scopes#provider-scope)), a new instance of the class will be created exclusively for each job. The instance will be garbage-collected after the job has completed.

0 commit comments

Comments
 (0)