Skip to content

Commit d2b257f

Browse files
committed
docs: use node: on import specifiers for builtin modules
1 parent fad7dcc commit d2b257f

File tree

8 files changed

+20
-20
lines changed

8 files changed

+20
-20
lines changed

content/fundamentals/dynamic-modules.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ That nicely handles passing an `options` object to our dynamic module. How do we
181181

182182
```typescript
183183
import { Injectable } from '@nestjs/common';
184+
import * as fs from 'node:fs';
185+
import * as path from 'node:path';
184186
import * as dotenv from 'dotenv';
185-
import * as fs from 'fs';
186-
import * as path from 'path';
187187
import { EnvConfig } from './interfaces';
188188

189189
@Injectable()
@@ -235,9 +235,9 @@ export class ConfigModule {
235235
Now we can complete the process by injecting the `'CONFIG_OPTIONS'` provider into the `ConfigService`. Recall that when we define a provider using a non-class token we need to use the `@Inject()` decorator [as described here](https://docs.nestjs.com/fundamentals/custom-providers#non-class-based-provider-tokens).
236236

237237
```typescript
238+
import * as fs from 'node:fs';
239+
import * as path from 'node:path';
238240
import * as dotenv from 'dotenv';
239-
import * as fs from 'fs';
240-
import * as path from 'path';
241241
import { Injectable, Inject } from '@nestjs/common';
242242
import { EnvConfig } from './interfaces';
243243

content/graphql/quick-start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ The above approach dynamically generates TypeScript definitions each time the ap
177177

178178
```typescript
179179
import { GraphQLDefinitionsFactory } from '@nestjs/graphql';
180-
import { join } from 'path';
180+
import { join } from 'node:path';
181181

182182
const definitionsFactory = new GraphQLDefinitionsFactory();
183183
definitionsFactory.generate({

content/security/encryption-hashing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Node.js provides a built-in [crypto module](https://nodejs.org/api/crypto.html)
1111
As an example, let's use AES (Advanced Encryption System) `'aes-256-ctr'` algorithm CTR encryption mode.
1212

1313
```typescript
14-
import { createCipheriv, randomBytes, scrypt } from 'crypto';
15-
import { promisify } from 'util';
14+
import { createCipheriv, randomBytes, scrypt } from 'node:crypto';
15+
import { promisify } from 'node:util';
1616

1717
const iv = randomBytes(16);
1818
const password = 'Password used to generate key';
@@ -32,7 +32,7 @@ const encryptedText = Buffer.concat([
3232
Now to decrypt `encryptedText` value:
3333

3434
```typescript
35-
import { createDecipheriv } from 'crypto';
35+
import { createDecipheriv } from 'node:crypto';
3636

3737
const decipher = createDecipheriv('aes-256-ctr', key, iv);
3838
const decryptedText = Buffer.concat([

content/techniques/compression.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ await app.register(compression);
4848
By default, `@fastify/compress` will use Brotli compression (on Node >= 11.7.0) when browsers indicate support for the encoding. While Brotli can be quite efficient in terms of compression ratio, it can also be quite slow. By default, Brotli sets a maximum compression quality of 11, although it can be adjusted to reduce compression time in lieu of compression quality by adjusting the `BROTLI_PARAM_QUALITY` between 0 min and 11 max. This will require fine tuning to optimize space/time performance. An example with quality 4:
4949

5050
```typescript
51-
import { constants } from 'zlib';
51+
import { constants } from 'node:zlib';
5252
// somewhere in your initialization file
5353
await app.register(compression, { brotliOptions: { params: { [constants.BROTLI_PARAM_QUALITY]: 4 } } });
5454
```

content/techniques/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ Once the package is installed, we use the `yaml#load` function to load the YAML
152152

153153
```typescript
154154
@@filename(config/configuration)
155-
import { readFileSync } from 'fs';
155+
import { readFileSync } from 'node:fs';
156+
import { join } from 'node:path';
156157
import * as yaml from 'js-yaml';
157-
import { join } from 'path';
158158
159159
const YAML_CONFIG_FILENAME = 'config.yaml';
160160

content/techniques/mvc.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ We've used the `hbs` ([Handlebars](https://github.com/pillarjs/hbs#readme)) engi
2121
@@filename(main)
2222
import { NestFactory } from '@nestjs/core';
2323
import { NestExpressApplication } from '@nestjs/platform-express';
24-
import { join } from 'path';
24+
import { join } from 'node:path';
2525
import { AppModule } from './app.module';
2626

2727
async function bootstrap() {
@@ -38,7 +38,7 @@ async function bootstrap() {
3838
bootstrap();
3939
@@switch
4040
import { NestFactory } from '@nestjs/core';
41-
import { join } from 'path';
41+
import { join } from 'node:path';
4242
import { AppModule } from './app.module';
4343

4444
async function bootstrap() {
@@ -139,7 +139,7 @@ The next steps cover almost the same process used with Express, with minor diffe
139139
import { NestFactory } from '@nestjs/core';
140140
import { NestFastifyApplication, FastifyAdapter } from '@nestjs/platform-fastify';
141141
import { AppModule } from './app.module';
142-
import { join } from 'path';
142+
import { join } from 'node:path';
143143

144144
async function bootstrap() {
145145
const app = await NestFactory.create<NestFastifyApplication>(
@@ -163,7 +163,7 @@ bootstrap();
163163
import { NestFactory } from '@nestjs/core';
164164
import { FastifyAdapter } from '@nestjs/platform-fastify';
165165
import { AppModule } from './app.module';
166-
import { join } from 'path';
166+
import { join } from 'node:path';
167167

168168
async function bootstrap() {
169169
const app = await NestFactory.create(AppModule, new FastifyAdapter());

content/techniques/queues.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ Job handlers can also be run in a separate (forked) process ([source](https://do
370370
@@filename(app.module)
371371
import { Module } from '@nestjs/common';
372372
import { BullModule } from '@nestjs/bullmq';
373-
import { join } from 'path';
373+
import { join } from 'node:path';
374374

375375
@Module({
376376
imports: [

content/techniques/streaming-files.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ You can find a simple example of returning the `package.json` as a file instead
3333

3434
```ts
3535
import { Controller, Get, StreamableFile } from '@nestjs/common';
36-
import { createReadStream } from 'fs';
37-
import { join } from 'path';
36+
import { createReadStream } from 'node:fs';
37+
import { join } from 'node:path';
3838

3939
@Controller('file')
4040
export class FileController {
@@ -50,8 +50,8 @@ The default content type (the value for `Content-Type` HTTP response header) is
5050

5151
```ts
5252
import { Controller, Get, StreamableFile, Res } from '@nestjs/common';
53-
import { createReadStream } from 'fs';
54-
import { join } from 'path';
53+
import { createReadStream } from 'node:fs';
54+
import { join } from 'node:path';
5555
import type { Response } from 'express'; // Assuming that we are using the ExpressJS HTTP Adapter
5656

5757
@Controller('file')

0 commit comments

Comments
 (0)