Skip to content

Commit 8b56dff

Browse files
committed
doc: fix inconsistencies in CJS code snippets
Signed-off-by: Antoine du Hamel <[email protected]> PR-URL: #63199 Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Ulises Gascón <[email protected]>
1 parent 6db6944 commit 8b56dff

16 files changed

Lines changed: 11 additions & 138 deletions

doc/api/assert.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ process.on('exit', () => {
353353

354354
```cjs
355355
const assert = require('node:assert');
356-
const process = require('node:process');
357356

358357
const tracker = new assert.CallTracker();
359358

doc/api/child_process.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,6 @@ the error passed to the callback will be an `AbortError`:
591591

592592
```cjs
593593
const { fork } = require('node:child_process');
594-
const process = require('node:process');
595594

596595
if (process.argv[2] === 'child') {
597596
setTimeout(() => {
@@ -933,7 +932,6 @@ Example of a long-running process, by detaching and also ignoring its parent
933932
934933
```cjs
935934
const { spawn } = require('node:child_process');
936-
const process = require('node:process');
937935

938936
const subprocess = spawn(process.argv[0], ['child_program.js'], {
939937
detached: true,
@@ -1077,7 +1075,6 @@ pipes between the parent and child. The value is one of the following:
10771075
10781076
```cjs
10791077
const { spawn } = require('node:child_process');
1080-
const process = require('node:process');
10811078

10821079
// Child will use parent's stdios.
10831080
spawn('prg', [], { stdio: 'inherit' });
@@ -1833,7 +1830,6 @@ process to wait for the child process to exit before exiting itself.
18331830
18341831
```cjs
18351832
const { spawn } = require('node:child_process');
1836-
const process = require('node:process');
18371833

18381834
const subprocess = spawn(process.argv[0], ['child_program.js'], {
18391835
detached: true,
@@ -2289,7 +2285,6 @@ the child and the parent processes.
22892285

22902286
```cjs
22912287
const { spawn } = require('node:child_process');
2292-
const process = require('node:process');
22932288
22942289
const subprocess = spawn(process.argv[0], ['child_program.js'], {
22952290
detached: true,

doc/api/cluster.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ if (cluster.isPrimary) {
4949
const cluster = require('node:cluster');
5050
const http = require('node:http');
5151
const numCPUs = require('node:os').availableParallelism();
52-
const process = require('node:process');
5352

5453
if (cluster.isPrimary) {
5554
console.log(`Primary ${process.pid} is running`);
@@ -318,7 +317,6 @@ if (cluster.isPrimary) {
318317
const cluster = require('node:cluster');
319318
const http = require('node:http');
320319
const numCPUs = require('node:os').availableParallelism();
321-
const process = require('node:process');
322320

323321
if (cluster.isPrimary) {
324322

@@ -541,7 +539,6 @@ if (cluster.isPrimary) {
541539
const cluster = require('node:cluster');
542540
const http = require('node:http');
543541
const numCPUs = require('node:os').availableParallelism();
544-
const process = require('node:process');
545542

546543
if (cluster.isPrimary) {
547544
console.log(`Primary ${process.pid} is running`);

doc/api/perf_hooks.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,6 @@ setImmediate(() => {
16781678
```
16791679

16801680
```cjs
1681-
'use strict';
16821681
const { eventLoopUtilization } = require('node:perf_hooks');
16831682
const { spawnSync } = require('node:child_process');
16841683

@@ -2126,7 +2125,6 @@ setTimeout(() => {}, 1000);
21262125
```
21272126

21282127
```cjs
2129-
'use strict';
21302128
const async_hooks = require('node:async_hooks');
21312129
const {
21322130
performance,
@@ -2194,7 +2192,6 @@ await timedImport('some-module');
21942192
<!-- eslint-disable no-global-assign -->
21952193

21962194
```cjs
2197-
'use strict';
21982195
const {
21992196
performance,
22002197
PerformanceObserver,
@@ -2251,7 +2248,6 @@ createServer((req, res) => {
22512248
```
22522249

22532250
```cjs
2254-
'use strict';
22552251
const { PerformanceObserver } = require('node:perf_hooks');
22562252
const http = require('node:http');
22572253

@@ -2293,7 +2289,6 @@ createServer((socket) => {
22932289
```
22942290

22952291
```cjs
2296-
'use strict';
22972292
const { PerformanceObserver } = require('node:perf_hooks');
22982293
const net = require('node:net');
22992294
const obs = new PerformanceObserver((items) => {
@@ -2327,7 +2322,6 @@ promises.resolve('localhost');
23272322
```
23282323

23292324
```cjs
2330-
'use strict';
23312325
const { PerformanceObserver } = require('node:perf_hooks');
23322326
const dns = require('node:dns');
23332327
const obs = new PerformanceObserver((items) => {

doc/api/process.md

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Node.js process.
1313
import process from 'node:process';
1414
```
1515

16+
<!-- eslint-disable no-restricted-syntax -->
17+
1618
```cjs
1719
const process = require('node:process');
1820
```
@@ -62,8 +64,6 @@ console.log('This message is displayed first.');
6264
```
6365

6466
```cjs
65-
const process = require('node:process');
66-
6767
process.on('beforeExit', (code) => {
6868
console.log('Process beforeExit event with code: ', code);
6969
});
@@ -120,8 +120,6 @@ process.on('exit', (code) => {
120120
```
121121

122122
```cjs
123-
const process = require('node:process');
124-
125123
process.on('exit', (code) => {
126124
console.log(`About to exit with code: ${code}`);
127125
});
@@ -143,8 +141,6 @@ process.on('exit', (code) => {
143141
```
144142

145143
```cjs
146-
const process = require('node:process');
147-
148144
process.on('exit', (code) => {
149145
setTimeout(() => {
150146
console.log('This will not run');
@@ -237,8 +233,6 @@ main().then(console.log);
237233
```
238234

239235
```cjs
240-
const process = require('node:process');
241-
242236
process.on('multipleResolves', (type, promise, reason) => {
243237
console.error(type, promise, reason);
244238
setImmediate(() => process.exit(1));
@@ -310,8 +304,6 @@ process.on('rejectionHandled', (promise) => {
310304
```
311305

312306
```cjs
313-
const process = require('node:process');
314-
315307
const unhandledRejections = new Map();
316308
process.on('unhandledRejection', (reason, promise) => {
317309
unhandledRejections.set(promise, reason);
@@ -394,7 +386,6 @@ console.log('This will not run.');
394386
```
395387

396388
```cjs
397-
const process = require('node:process');
398389
const fs = require('node:fs');
399390

400391
process.on('uncaughtException', (err, origin) => {
@@ -483,8 +474,6 @@ nonexistentFunc();
483474
```
484475

485476
```cjs
486-
const process = require('node:process');
487-
488477
process.on('uncaughtExceptionMonitor', (err, origin) => {
489478
MyMonitoringTool.logSync(err, origin);
490479
});
@@ -534,8 +523,6 @@ somePromise.then((res) => {
534523
```
535524

536525
```cjs
537-
const process = require('node:process');
538-
539526
process.on('unhandledRejection', (reason, promise) => {
540527
console.log('Unhandled Rejection at:', promise, 'reason:', reason);
541528
// Application specific logging, throwing an error, or other logic here
@@ -562,8 +549,6 @@ const resource = new SomeResource();
562549
```
563550

564551
```cjs
565-
const process = require('node:process');
566-
567552
function SomeResource() {
568553
// Initially set the loaded status to a rejected promise
569554
this.loaded = Promise.reject(new Error('Resource not yet loaded!'));
@@ -615,8 +600,6 @@ process.on('warning', (warning) => {
615600
```
616601

617602
```cjs
618-
const process = require('node:process');
619-
620603
process.on('warning', (warning) => {
621604
console.warn(warning.name); // Print the warning name
622605
console.warn(warning.message); // Print the warning message
@@ -752,8 +735,6 @@ process.on('SIGTERM', handle);
752735
```
753736

754737
```cjs
755-
const process = require('node:process');
756-
757738
// Begin reading from stdin so the process does not exit.
758739
process.stdin.resume();
759740

@@ -1262,8 +1243,6 @@ process.debugPort = 5858;
12621243
```
12631244

12641245
```cjs
1265-
const process = require('node:process');
1266-
12671246
process.debugPort = 5858;
12681247
```
12691248

@@ -1400,8 +1379,6 @@ process.on('warning', (warning) => {
14001379
```
14011380
14021381
```cjs
1403-
const process = require('node:process');
1404-
14051382
process.on('warning', (warning) => {
14061383
console.warn(warning.name); // 'Warning'
14071384
console.warn(warning.message); // 'Something happened!'
@@ -1493,8 +1470,6 @@ process.on('warning', (warning) => {
14931470
```
14941471
14951472
```cjs
1496-
const process = require('node:process');
1497-
14981473
process.on('warning', (warning) => {
14991474
console.warn(warning.name);
15001475
console.warn(warning.message);
@@ -1888,8 +1863,6 @@ if (someConditionNotMet()) {
18881863
```
18891864
18901865
```cjs
1891-
const process = require('node:process');
1892-
18931866
// How to properly set the exit code while letting
18941867
// the process exit gracefully.
18951868
if (someConditionNotMet()) {
@@ -2425,8 +2398,6 @@ if (process.getegid) {
24252398
```
24262399
24272400
```cjs
2428-
const process = require('node:process');
2429-
24302401
if (process.getegid) {
24312402
console.log(`Current gid: ${process.getegid()}`);
24322403
}
@@ -2455,8 +2426,6 @@ if (process.geteuid) {
24552426
```
24562427
24572428
```cjs
2458-
const process = require('node:process');
2459-
24602429
if (process.geteuid) {
24612430
console.log(`Current uid: ${process.geteuid()}`);
24622431
}
@@ -2485,8 +2454,6 @@ if (process.getgid) {
24852454
```
24862455
24872456
```cjs
2488-
const process = require('node:process');
2489-
24902457
if (process.getgid) {
24912458
console.log(`Current gid: ${process.getgid()}`);
24922459
}
@@ -2516,8 +2483,6 @@ if (process.getgroups) {
25162483
```
25172484
25182485
```cjs
2519-
const process = require('node:process');
2520-
25212486
if (process.getgroups) {
25222487
console.log(process.getgroups()); // [ 16, 21, 297 ]
25232488
}
@@ -2546,8 +2511,6 @@ if (process.getuid) {
25462511
```
25472512
25482513
```cjs
2549-
const process = require('node:process');
2550-
25512514
if (process.getuid) {
25522515
console.log(`Current uid: ${process.getuid()}`);
25532516
}
@@ -2752,8 +2715,6 @@ kill(process.pid, 'SIGHUP');
27522715
```
27532716
27542717
```cjs
2755-
const process = require('node:process');
2756-
27572718
process.on('SIGHUP', () => {
27582719
console.log('Got SIGHUP signal.');
27592720
});
@@ -3864,8 +3825,6 @@ if (process.getegid && process.setegid) {
38643825
```
38653826
38663827
```cjs
3867-
const process = require('node:process');
3868-
38693828
if (process.getegid && process.setegid) {
38703829
console.log(`Current gid: ${process.getegid()}`);
38713830
try {
@@ -3909,8 +3868,6 @@ if (process.geteuid && process.seteuid) {
39093868
```
39103869
39113870
```cjs
3912-
const process = require('node:process');
3913-
39143871
if (process.geteuid && process.seteuid) {
39153872
console.log(`Current uid: ${process.geteuid()}`);
39163873
try {
@@ -3954,8 +3911,6 @@ if (process.getgid && process.setgid) {
39543911
```
39553912
39563913
```cjs
3957-
const process = require('node:process');
3958-
39593914
if (process.getgid && process.setgid) {
39603915
console.log(`Current gid: ${process.getgid()}`);
39613916
try {
@@ -3999,8 +3954,6 @@ if (process.getgroups && process.setgroups) {
39993954
```
40003955
40013956
```cjs
4002-
const process = require('node:process');
4003-
40043957
if (process.getgroups && process.setgroups) {
40053958
try {
40063959
process.setgroups([501]);
@@ -4043,8 +3996,6 @@ if (process.getuid && process.setuid) {
40433996
```
40443997
40453998
```cjs
4046-
const process = require('node:process');
4047-
40483999
if (process.getuid && process.setuid) {
40494000
console.log(`Current uid: ${process.getuid()}`);
40504001
try {

doc/api/sqlite.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ console.log(query.all());
5959
```
6060

6161
```cjs
62-
'use strict';
6362
const { DatabaseSync } = require('node:sqlite');
6463
const database = new DatabaseSync(':memory:');
6564

@@ -316,7 +315,6 @@ database.loadExtension('./base64.dylib', 'sqlite3_base64_init');
316315
```
317316

318317
```cjs
319-
'use strict';
320318
const { DatabaseSync } = require('node:sqlite');
321319
const database = new DatabaseSync(':memory:', { allowExtension: true });
322320

doc/api/test.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,6 @@ test('spies on a function', () => {
850850
```
851851

852852
```cjs
853-
'use strict';
854853
const assert = require('node:assert');
855854
const { mock, test } = require('node:test');
856855

doc/api/tracing.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,6 @@ collect();
326326
```
327327

328328
```cjs
329-
'use strict';
330-
331329
const { Session } = require('node:inspector');
332330
const session = new Session();
333331
session.connect();

0 commit comments

Comments
 (0)