Skip to content

docs: use node: on import specifiers of code snippets for builtin modules #3239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions content/fundamentals/dynamic-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion content/graphql/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
6 changes: 3 additions & 3 deletions content/security/encryption-hashing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion content/techniques/compression.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 } } });
```
Expand Down
4 changes: 2 additions & 2 deletions content/techniques/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
8 changes: 4 additions & 4 deletions content/techniques/mvc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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>(
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion content/techniques/queues.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
8 changes: 4 additions & 4 deletions content/techniques/streaming-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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')
Expand Down