diff --git a/content/fundamentals/dynamic-modules.md b/content/fundamentals/dynamic-modules.md index f1a3a8731e..6e2db4147f 100644 --- a/content/fundamentals/dynamic-modules.md +++ b/content/fundamentals/dynamic-modules.md @@ -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'; diff --git a/content/graphql/quick-start.md b/content/graphql/quick-start.md index f68f65c997..90a16dbb2e 100644 --- a/content/graphql/quick-start.md +++ b/content/graphql/quick-start.md @@ -178,7 +178,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({ diff --git a/content/security/encryption-hashing.md b/content/security/encryption-hashing.md index 71691d4927..518ee52203 100644 --- a/content/security/encryption-hashing.md +++ b/content/security/encryption-hashing.md @@ -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([ diff --git a/content/techniques/compression.md b/content/techniques/compression.md index 46244a4769..ca1fdcfb3d 100644 --- a/content/techniques/compression.md +++ b/content/techniques/compression.md @@ -42,7 +42,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 } } }); ``` diff --git a/content/techniques/configuration.md b/content/techniques/configuration.md index c0574bd8e1..0eb49df0aa 100644 --- a/content/techniques/configuration.md +++ b/content/techniques/configuration.md @@ -152,9 +152,9 @@ Once the package is installed, we use `yaml#load` function to load YAML file we ```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'; diff --git a/content/techniques/mvc.md b/content/techniques/mvc.md index e2d88e717d..f0c06f4301 100644 --- a/content/techniques/mvc.md +++ b/content/techniques/mvc.md @@ -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( @@ -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()); diff --git a/content/techniques/queues.md b/content/techniques/queues.md index 6e0354923e..39510227cd 100644 --- a/content/techniques/queues.md +++ b/content/techniques/queues.md @@ -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: [ diff --git a/content/techniques/streaming-files.md b/content/techniques/streaming-files.md index 13bad1cadc..863abecd37 100644 --- a/content/techniques/streaming-files.md +++ b/content/techniques/streaming-files.md @@ -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')