docs: use node: on import specifiers for builtin modules

This commit is contained in:
Micael Levi L. Cavalcante
2025-03-30 11:48:53 -04:00
parent fad7dcc101
commit d2b257f8af
8 changed files with 20 additions and 20 deletions

View File

@@ -181,9 +181,9 @@ That nicely handles passing an `options` object to our dynamic module. How do we
```typescript
import { Injectable } from '@nestjs/common';
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as dotenv from 'dotenv';
import * as fs from 'fs';
import * as path from 'path';
import { EnvConfig } from './interfaces';
@Injectable()
@@ -235,9 +235,9 @@ export class ConfigModule {
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).
```typescript
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as dotenv from 'dotenv';
import * as fs from 'fs';
import * as path from 'path';
import { Injectable, Inject } from '@nestjs/common';
import { EnvConfig } from './interfaces';

View File

@@ -177,7 +177,7 @@ The above approach dynamically generates TypeScript definitions each time the ap
```typescript
import { GraphQLDefinitionsFactory } from '@nestjs/graphql';
import { join } from 'path';
import { join } from 'node:path';
const definitionsFactory = new GraphQLDefinitionsFactory();
definitionsFactory.generate({

View File

@@ -11,8 +11,8 @@ Node.js provides a built-in [crypto module](https://nodejs.org/api/crypto.html)
As an example, let's use AES (Advanced Encryption System) `'aes-256-ctr'` algorithm CTR encryption mode.
```typescript
import { createCipheriv, randomBytes, scrypt } from 'crypto';
import { promisify } from 'util';
import { createCipheriv, randomBytes, scrypt } from 'node:crypto';
import { promisify } from 'node:util';
const iv = randomBytes(16);
const password = 'Password used to generate key';
@@ -32,7 +32,7 @@ const encryptedText = Buffer.concat([
Now to decrypt `encryptedText` value:
```typescript
import { createDecipheriv } from 'crypto';
import { createDecipheriv } from 'node:crypto';
const decipher = createDecipheriv('aes-256-ctr', key, iv);
const decryptedText = Buffer.concat([

View File

@@ -48,7 +48,7 @@ await app.register(compression);
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:
```typescript
import { constants } from 'zlib';
import { constants } from 'node:zlib';
// somewhere in your initialization file
await app.register(compression, { brotliOptions: { params: { [constants.BROTLI_PARAM_QUALITY]: 4 } } });
```

View File

@@ -152,9 +152,9 @@ Once the package is installed, we use the `yaml#load` function to load the YAML
```typescript
@@filename(config/configuration)
import { readFileSync } from 'fs';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import * as yaml from 'js-yaml';
import { join } from 'path';
const YAML_CONFIG_FILENAME = 'config.yaml';

View File

@@ -21,7 +21,7 @@ We've used the `hbs` ([Handlebars](https://github.com/pillarjs/hbs#readme)) engi
@@filename(main)
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { join } from 'path';
import { join } from 'node:path';
import { AppModule } from './app.module';
async function bootstrap() {
@@ -38,7 +38,7 @@ async function bootstrap() {
bootstrap();
@@switch
import { NestFactory } from '@nestjs/core';
import { join } from 'path';
import { join } from 'node:path';
import { AppModule } from './app.module';
async function bootstrap() {
@@ -139,7 +139,7 @@ The next steps cover almost the same process used with Express, with minor diffe
import { NestFactory } from '@nestjs/core';
import { NestFastifyApplication, FastifyAdapter } from '@nestjs/platform-fastify';
import { AppModule } from './app.module';
import { join } from 'path';
import { join } from 'node:path';
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
@@ -163,7 +163,7 @@ bootstrap();
import { NestFactory } from '@nestjs/core';
import { FastifyAdapter } from '@nestjs/platform-fastify';
import { AppModule } from './app.module';
import { join } from 'path';
import { join } from 'node:path';
async function bootstrap() {
const app = await NestFactory.create(AppModule, new FastifyAdapter());

View File

@@ -370,7 +370,7 @@ Job handlers can also be run in a separate (forked) process ([source](https://do
@@filename(app.module)
import { Module } from '@nestjs/common';
import { BullModule } from '@nestjs/bullmq';
import { join } from 'path';
import { join } from 'node:path';
@Module({
imports: [

View File

@@ -33,8 +33,8 @@ You can find a simple example of returning the `package.json` as a file instead
```ts
import { Controller, Get, StreamableFile } from '@nestjs/common';
import { createReadStream } from 'fs';
import { join } from 'path';
import { createReadStream } from 'node:fs';
import { join } from 'node:path';
@Controller('file')
export class FileController {
@@ -50,8 +50,8 @@ The default content type (the value for `Content-Type` HTTP response header) is
```ts
import { Controller, Get, StreamableFile, Res } from '@nestjs/common';
import { createReadStream } from 'fs';
import { join } from 'path';
import { createReadStream } from 'node:fs';
import { join } from 'node:path';
import type { Response } from 'express'; // Assuming that we are using the ExpressJS HTTP Adapter
@Controller('file')