Skip to content

Commit ca2a4b6

Browse files
committed
doc: fix inconsistencies in CJS code snippets
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 2b6ce13 commit ca2a4b6

15 files changed

Lines changed: 11 additions & 136 deletions

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
@@ -1682,7 +1682,6 @@ setImmediate(() => {
16821682
```
16831683

16841684
```cjs
1685-
'use strict';
16861685
const { eventLoopUtilization } = require('node:perf_hooks');
16871686
const { spawnSync } = require('node:child_process');
16881687

@@ -2132,7 +2131,6 @@ setTimeout(() => {}, 1000);
21322131
```
21332132

21342133
```cjs
2135-
'use strict';
21362134
const async_hooks = require('node:async_hooks');
21372135
const {
21382136
performance,
@@ -2202,7 +2200,6 @@ await timedImport('some-module');
22022200
<!-- eslint-disable no-global-assign -->
22032201

22042202
```cjs
2205-
'use strict';
22062203
const {
22072204
performance,
22082205
PerformanceObserver,
@@ -2259,7 +2256,6 @@ createServer((req, res) => {
22592256
```
22602257

22612258
```cjs
2262-
'use strict';
22632259
const { PerformanceObserver } = require('node:perf_hooks');
22642260
const http = require('node:http');
22652261

@@ -2301,7 +2297,6 @@ createServer((socket) => {
23012297
```
23022298

23032299
```cjs
2304-
'use strict';
23052300
const { PerformanceObserver } = require('node:perf_hooks');
23062301
const net = require('node:net');
23072302
const obs = new PerformanceObserver((items) => {
@@ -2335,7 +2330,6 @@ promises.resolve('localhost');
23352330
```
23362331

23372332
```cjs
2338-
'use strict';
23392333
const { PerformanceObserver } = require('node:perf_hooks');
23402334
const dns = require('node:dns');
23412335
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');
@@ -221,8 +217,6 @@ process.on('rejectionHandled', (promise) => {
221217
```
222218

223219
```cjs
224-
const process = require('node:process');
225-
226220
const unhandledRejections = new Map();
227221
process.on('unhandledRejection', (reason, promise) => {
228222
unhandledRejections.set(promise, reason);
@@ -305,7 +299,6 @@ console.log('This will not run.');
305299
```
306300

307301
```cjs
308-
const process = require('node:process');
309302
const fs = require('node:fs');
310303

311304
process.on('uncaughtException', (err, origin) => {
@@ -394,8 +387,6 @@ nonexistentFunc();
394387
```
395388

396389
```cjs
397-
const process = require('node:process');
398-
399390
process.on('uncaughtExceptionMonitor', (err, origin) => {
400391
MyMonitoringTool.logSync(err, origin);
401392
});
@@ -445,8 +436,6 @@ somePromise.then((res) => {
445436
```
446437

447438
```cjs
448-
const process = require('node:process');
449-
450439
process.on('unhandledRejection', (reason, promise) => {
451440
console.log('Unhandled Rejection at:', promise, 'reason:', reason);
452441
// Application specific logging, throwing an error, or other logic here
@@ -473,8 +462,6 @@ const resource = new SomeResource();
473462
```
474463

475464
```cjs
476-
const process = require('node:process');
477-
478465
function SomeResource() {
479466
// Initially set the loaded status to a rejected promise
480467
this.loaded = Promise.reject(new Error('Resource not yet loaded!'));
@@ -526,8 +513,6 @@ process.on('warning', (warning) => {
526513
```
527514

528515
```cjs
529-
const process = require('node:process');
530-
531516
process.on('warning', (warning) => {
532517
console.warn(warning.name); // Print the warning name
533518
console.warn(warning.message); // Print the warning message
@@ -663,8 +648,6 @@ process.on('SIGTERM', handle);
663648
```
664649

665650
```cjs
666-
const process = require('node:process');
667-
668651
// Begin reading from stdin so the process does not exit.
669652
process.stdin.resume();
670653

@@ -767,8 +750,6 @@ process.addUncaughtExceptionCaptureCallback((err) => {
767750
```
768751

769752
```cjs
770-
const process = require('node:process');
771-
772753
process.addUncaughtExceptionCaptureCallback((err) => {
773754
console.error('Caught exception:', err.message);
774755
return true; // Indicates exception was handled
@@ -1218,8 +1199,6 @@ process.debugPort = 5858;
12181199
```
12191200

12201201
```cjs
1221-
const process = require('node:process');
1222-
12231202
process.debugPort = 5858;
12241203
```
12251204

@@ -1356,8 +1335,6 @@ process.on('warning', (warning) => {
13561335
```
13571336
13581337
```cjs
1359-
const process = require('node:process');
1360-
13611338
process.on('warning', (warning) => {
13621339
console.warn(warning.name); // 'Warning'
13631340
console.warn(warning.message); // 'Something happened!'
@@ -1449,8 +1426,6 @@ process.on('warning', (warning) => {
14491426
```
14501427
14511428
```cjs
1452-
const process = require('node:process');
1453-
14541429
process.on('warning', (warning) => {
14551430
console.warn(warning.name);
14561431
console.warn(warning.message);
@@ -1866,8 +1841,6 @@ if (someConditionNotMet()) {
18661841
```
18671842
18681843
```cjs
1869-
const process = require('node:process');
1870-
18711844
// How to properly set the exit code while letting
18721845
// the process exit gracefully.
18731846
if (someConditionNotMet()) {
@@ -2409,8 +2382,6 @@ if (process.getegid) {
24092382
```
24102383
24112384
```cjs
2412-
const process = require('node:process');
2413-
24142385
if (process.getegid) {
24152386
console.log(`Current gid: ${process.getegid()}`);
24162387
}
@@ -2439,8 +2410,6 @@ if (process.geteuid) {
24392410
```
24402411
24412412
```cjs
2442-
const process = require('node:process');
2443-
24442413
if (process.geteuid) {
24452414
console.log(`Current uid: ${process.geteuid()}`);
24462415
}
@@ -2469,8 +2438,6 @@ if (process.getgid) {
24692438
```
24702439
24712440
```cjs
2472-
const process = require('node:process');
2473-
24742441
if (process.getgid) {
24752442
console.log(`Current gid: ${process.getgid()}`);
24762443
}
@@ -2500,8 +2467,6 @@ if (process.getgroups) {
25002467
```
25012468
25022469
```cjs
2503-
const process = require('node:process');
2504-
25052470
if (process.getgroups) {
25062471
console.log(process.getgroups()); // [ 16, 21, 297 ]
25072472
}
@@ -2530,8 +2495,6 @@ if (process.getuid) {
25302495
```
25312496
25322497
```cjs
2533-
const process = require('node:process');
2534-
25352498
if (process.getuid) {
25362499
console.log(`Current uid: ${process.getuid()}`);
25372500
}
@@ -2736,8 +2699,6 @@ kill(process.pid, 'SIGHUP');
27362699
```
27372700
27382701
```cjs
2739-
const process = require('node:process');
2740-
27412702
process.on('SIGHUP', () => {
27422703
console.log('Got SIGHUP signal.');
27432704
});
@@ -3853,8 +3814,6 @@ if (process.getegid && process.setegid) {
38533814
```
38543815
38553816
```cjs
3856-
const process = require('node:process');
3857-
38583817
if (process.getegid && process.setegid) {
38593818
console.log(`Current gid: ${process.getegid()}`);
38603819
try {
@@ -3898,8 +3857,6 @@ if (process.geteuid && process.seteuid) {
38983857
```
38993858
39003859
```cjs
3901-
const process = require('node:process');
3902-
39033860
if (process.geteuid && process.seteuid) {
39043861
console.log(`Current uid: ${process.geteuid()}`);
39053862
try {
@@ -3943,8 +3900,6 @@ if (process.getgid && process.setgid) {
39433900
```
39443901
39453902
```cjs
3946-
const process = require('node:process');
3947-
39483903
if (process.getgid && process.setgid) {
39493904
console.log(`Current gid: ${process.getgid()}`);
39503905
try {
@@ -3988,8 +3943,6 @@ if (process.getgroups && process.setgroups) {
39883943
```
39893944
39903945
```cjs
3991-
const process = require('node:process');
3992-
39933946
if (process.getgroups && process.setgroups) {
39943947
try {
39953948
process.setgroups([501]);
@@ -4032,8 +3985,6 @@ if (process.getuid && process.setuid) {
40323985
```
40333986
40343987
```cjs
4035-
const process = require('node:process');
4036-
40373988
if (process.getuid && process.setuid) {
40383989
console.log(`Current uid: ${process.getuid()}`);
40393990
try {

doc/api/sqlite.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ console.log(query.all());
6161
```
6262

6363
```cjs
64-
'use strict';
6564
const { DatabaseSync } = require('node:sqlite');
6665
const database = new DatabaseSync(':memory:');
6766

doc/api/test.md

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

853853
```cjs
854-
'use strict';
855854
const assert = require('node:assert');
856855
const { mock, test } = require('node:test');
857856

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();

doc/api/v8.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ stream.pipe(process.stdout);
107107
```js
108108
// Print heap snapshot to the console
109109
const v8 = require('node:v8');
110-
const process = require('node:process');
111110
const stream = v8.getHeapSnapshot();
112111
stream.pipe(process.stdout);
113112
```
@@ -1313,8 +1312,6 @@ objects during deserialization of the snapshot. For example, if the `entry.js`
13131312
contains the following script:
13141313
13151314
```cjs
1316-
'use strict';
1317-
13181315
const fs = require('node:fs');
13191316
const zlib = require('node:zlib');
13201317
const path = require('node:path');

0 commit comments

Comments
 (0)