@@ -11,11 +11,11 @@ These objects are available in all modules.
11
11
The following variables may appear to be global but are not. They exist only in
12
12
the scope of [ CommonJS modules] [ ] :
13
13
14
- * [ ` __dirname ` ] [ ]
15
- * [ ` __filename ` ] [ ]
16
- * [ ` exports ` ] [ ]
17
- * [ ` module ` ] [ ]
18
- * [ ` require() ` ] [ ]
14
+ - [ ` __dirname ` ] [ ]
15
+ - [ ` __filename ` ] [ ]
16
+ - [ ` exports ` ] [ ]
17
+ - [ ` module ` ] [ ]
18
+ - [ ` require() ` ] [ ]
19
19
20
20
The objects listed here are specific to Node.js. There are [ built-in objects] [ ]
21
21
that are part of the JavaScript language itself, which are also globally
@@ -39,12 +39,13 @@ The API is based on the Web API {AbortController}.
39
39
``` js
40
40
const ac = new AbortController ();
41
41
42
- ac .signal .addEventListener (' abort' , () => console .log (' Aborted!' ),
43
- { once: true });
42
+ ac .signal .addEventListener (' abort' , () => console .log (' Aborted!' ), {
43
+ once: true ,
44
+ });
44
45
45
46
ac .abort ();
46
47
47
- console .log (ac .signal .aborted ); // Prints true
48
+ console .log (ac .signal .aborted ); // Prints true
48
49
```
49
50
50
51
### ` abortController.abort([reason]) `
@@ -61,7 +62,7 @@ changes:
61
62
description: Added the new optional reason argument.
62
63
-->
63
64
64
- * ` reason ` {any} An optional reason, retrievable on the ` AbortSignal ` 's
65
+ - ` reason ` {any} An optional reason, retrievable on the ` AbortSignal ` 's
65
66
` reason ` property.
66
67
67
68
Triggers the abort signal, causing the ` abortController.signal ` to emit
75
76
- v14.17.0
76
77
-->
77
78
78
- * Type: {AbortSignal}
79
+ - Type: {AbortSignal}
79
80
80
81
### Class: ` AbortSignal `
81
82
85
86
- v14.17.0
86
87
-->
87
88
88
- * Extends: {EventTarget}
89
+ - Extends: {EventTarget}
89
90
90
91
The ` AbortSignal ` is used to notify observers when the
91
92
` abortController.abort() ` method is called.
@@ -104,8 +105,8 @@ changes:
104
105
description: Added the new optional reason argument.
105
106
-->
106
107
107
- * ` reason ` {any}
108
- * Returns: {AbortSignal}
108
+ - ` reason ` {any}
109
+ - Returns: {AbortSignal}
109
110
110
111
Returns a new already aborted ` AbortSignal ` .
111
112
@@ -117,7 +118,7 @@ added:
117
118
- v16.14.0
118
119
-->
119
120
120
- * ` delay ` {number} The number of milliseconds to wait before triggering
121
+ - ` delay ` {number} The number of milliseconds to wait before triggering
121
122
the AbortSignal.
122
123
123
124
Returns a new ` AbortSignal ` which will be aborted in ` delay ` milliseconds.
@@ -130,7 +131,7 @@ added:
130
131
- v18.17.0
131
132
-->
132
133
133
- * ` signals ` {AbortSignal\[ ] } The ` AbortSignal ` s of which to compose a new ` AbortSignal ` .
134
+ - ` signals ` {AbortSignal\[ ] } The ` AbortSignal ` s of which to compose a new ` AbortSignal ` .
134
135
135
136
Returns a new ` AbortSignal ` which will be aborted if any of the provided
136
137
signals are aborted. Its [ ` abortSignal.reason ` ] [ ] will be set to whichever
@@ -155,9 +156,13 @@ const ac = new AbortController();
155
156
ac .signal .onabort = () => console .log (' aborted!' );
156
157
157
158
// Or the EventTarget API...
158
- ac .signal .addEventListener (' abort' , (event ) => {
159
- console .log (event .type ); // Prints 'abort'
160
- }, { once: true });
159
+ ac .signal .addEventListener (
160
+ ' abort' ,
161
+ (event ) => {
162
+ console .log (event .type ); // Prints 'abort'
163
+ },
164
+ { once: true }
165
+ );
161
166
162
167
ac .abort ();
163
168
```
@@ -181,7 +186,7 @@ added:
181
186
- v14.17.0
182
187
-->
183
188
184
- * Type: {boolean} True after the ` AbortController ` has been aborted.
189
+ - Type: {boolean} True after the ` AbortController ` has been aborted.
185
190
186
191
#### ` abortSignal.onabort `
187
192
@@ -191,7 +196,7 @@ added:
191
196
- v14.17.0
192
197
-->
193
198
194
- * Type: {Function}
199
+ - Type: {Function}
195
200
196
201
An optional callback function that may be set by user code to be notified
197
202
when the ` abortController.abort() ` function has been called.
@@ -204,14 +209,14 @@ added:
204
209
- v16.14.0
205
210
-->
206
211
207
- * Type: {any}
212
+ - Type: {any}
208
213
209
214
An optional reason specified when the ` AbortSignal ` was triggered.
210
215
211
216
``` js
212
217
const ac = new AbortController ();
213
218
ac .abort (new Error (' boom!' ));
214
- console .log (ac .signal .reason ); // Error: boom!
219
+ console .log (ac .signal .reason ); // Error: boom!
215
220
```
216
221
217
222
#### ` abortSignal.throwIfAborted() `
@@ -238,7 +243,7 @@ See {Blob}.
238
243
added: v0.1.103
239
244
-->
240
245
241
- * Type: {Function}
246
+ - Type: {Function}
242
247
243
248
Used to handle binary data. See the [ buffer section] [ ] .
244
249
@@ -348,7 +353,7 @@ A browser-compatible implementation of [`CompressionStream`][].
348
353
added: v0.1.100
349
354
-->
350
355
351
- * Type: {Object}
356
+ - Type: {Object}
352
357
353
358
Used to print to stdout and stderr. See the [ ` console ` ] [ ] section.
354
359
@@ -541,6 +546,15 @@ The implementation is based upon [undici](https://undici.nodejs.org), an HTTP/1.
541
546
written from scratch for Node.js. You can figure out which version of ` undici ` is bundled
542
547
in your Node.js process reading the ` process.versions.undici ` property.
543
548
549
+ ### Differences from standard fetch
550
+
551
+ Node.js provides a ` fetch() ` implementation that is similar to the web standard but with a few notable differences:
552
+
553
+ - ` new Response(asyncIterable) ` is supported, which is not in the standard.
554
+ - Cookies are not automatically handled.
555
+ - The forbidden headers list is not enforced.
556
+ - Other subtle differences may exist; consult the implementation details.
557
+
544
558
### Custom dispatcher
545
559
546
560
You can use a custom dispatcher to dispatch requests passing it in fetch's options object.
@@ -564,10 +578,10 @@ setGlobalDispatcher(new MyAgent());
564
578
565
579
The following globals are available to use with ` fetch ` :
566
580
567
- * [ ` FormData ` ] ( https://nodejs.org/api/globals.html#class-formdata )
568
- * [ ` Headers ` ] ( https://nodejs.org/api/globals.html#class-headers )
569
- * [ ` Request ` ] ( https://nodejs.org/api/globals.html#request )
570
- * [ ` Response ` ] ( https://nodejs.org/api/globals.html#response ) .
581
+ - [ ` FormData ` ] ( https://nodejs.org/api/globals.html#class-formdata )
582
+ - [ ` Headers ` ] ( https://nodejs.org/api/globals.html#class-headers )
583
+ - [ ` Request ` ] ( https://nodejs.org/api/globals.html#request )
584
+ - [ ` Response ` ] ( https://nodejs.org/api/globals.html#response ) .
571
585
572
586
## Class: ` File `
573
587
@@ -603,7 +617,7 @@ added: v0.1.27
603
617
604
618
> Stability: 3 - Legacy. Use [ ` globalThis ` ] [ ] instead.
605
619
606
- * Type: {Object} The global namespace object.
620
+ - Type: {Object} The global namespace object.
607
621
608
622
In browsers, the top-level scope has traditionally been the global scope. This
609
623
means that ` var something ` will define a new global variable, except within
@@ -702,13 +716,15 @@ A partial implementation of [`window.navigator`][].
702
716
added: v21.0.0
703
717
-->
704
718
705
- * Type: {number}
719
+ - Type: {number}
706
720
707
721
The ` navigator.hardwareConcurrency ` read-only property returns the number of
708
722
logical processors available to the current Node.js instance.
709
723
710
724
``` js
711
- console .log (` This process is running on ${ navigator .hardwareConcurrency } logical processors` );
725
+ console .log (
726
+ ` This process is running on ${ navigator .hardwareConcurrency } logical processors`
727
+ );
712
728
```
713
729
714
730
### ` navigator.language `
@@ -717,7 +733,7 @@ console.log(`This process is running on ${navigator.hardwareConcurrency} logical
717
733
added: v21.2.0
718
734
-->
719
735
720
- * Type: {string}
736
+ - Type: {string}
721
737
722
738
The ` navigator.language ` read-only property returns a string representing the
723
739
preferred language of the Node.js instance. The language will be determined by
@@ -729,7 +745,9 @@ The value is representing the language version as defined in [RFC 5646][].
729
745
The fallback value on builds without ICU is ` 'en-US' ` .
730
746
731
747
``` js
732
- console .log (` The preferred language of the Node.js instance has the tag '${ navigator .language } '` );
748
+ console .log (
749
+ ` The preferred language of the Node.js instance has the tag '${ navigator .language } '`
750
+ );
733
751
```
734
752
735
753
### ` navigator.languages `
@@ -738,7 +756,7 @@ console.log(`The preferred language of the Node.js instance has the tag '${navig
738
756
added: v21.2.0
739
757
-->
740
758
741
- * Type: {Array<string >}
759
+ - Type: {Array<string >}
742
760
743
761
The ` navigator.languages ` read-only property returns an array of strings
744
762
representing the preferred languages of the Node.js instance.
@@ -758,7 +776,7 @@ console.log(`The preferred languages are '${navigator.languages}'`);
758
776
added: v21.2.0
759
777
-->
760
778
761
- * Type: {string}
779
+ - Type: {string}
762
780
763
781
The ` navigator.platform ` read-only property returns a string identifying the
764
782
platform on which the Node.js instance is running.
@@ -773,7 +791,7 @@ console.log(`This process is running on ${navigator.platform}`);
773
791
added: v21.1.0
774
792
-->
775
793
776
- * Type: {string}
794
+ - Type: {string}
777
795
778
796
The ` navigator.userAgent ` read-only property returns user agent
779
797
consisting of the runtime name and major version number.
@@ -804,29 +822,37 @@ await navigator.locks.request('my_resource', async (lock) => {
804
822
});
805
823
806
824
// Request a shared lock
807
- await navigator .locks .request (' shared_resource' , { mode: ' shared' }, async (lock ) => {
808
- // Multiple shared locks can be held simultaneously
809
- console .log (` Shared lock acquired: ${ lock .name } ` );
810
- });
825
+ await navigator .locks .request (
826
+ ' shared_resource' ,
827
+ { mode: ' shared' },
828
+ async (lock ) => {
829
+ // Multiple shared locks can be held simultaneously
830
+ console .log (` Shared lock acquired: ${ lock .name } ` );
831
+ }
832
+ );
811
833
```
812
834
813
835
``` cjs
814
836
// Request an exclusive lock
815
- navigator .locks .request (' my_resource' , async (lock ) => {
816
- // The lock has been acquired.
817
- console .log (` Lock acquired: ${ lock .name } ` );
818
- // Lock is automatically released when the function returns
819
- }).then (() => {
820
- console .log (' Lock released' );
821
- });
837
+ navigator .locks
838
+ .request (' my_resource' , async (lock ) => {
839
+ // The lock has been acquired.
840
+ console .log (` Lock acquired: ${ lock .name } ` );
841
+ // Lock is automatically released when the function returns
842
+ })
843
+ .then (() => {
844
+ console .log (' Lock released' );
845
+ });
822
846
823
847
// Request a shared lock
824
- navigator .locks .request (' shared_resource' , { mode: ' shared' }, async (lock ) => {
825
- // Multiple shared locks can be held simultaneously
826
- console .log (` Shared lock acquired: ${ lock .name } ` );
827
- }).then (() => {
828
- console .log (' Shared lock released' );
829
- });
848
+ navigator .locks
849
+ .request (' shared_resource' , { mode: ' shared' }, async (lock ) => {
850
+ // Multiple shared locks can be held simultaneously
851
+ console .log (` Shared lock acquired: ${ lock .name } ` );
852
+ })
853
+ .then (() => {
854
+ console .log (' Shared lock released' );
855
+ });
830
856
```
831
857
832
858
See [ ` worker.locks ` ] [ ] for detailed API documentation.
@@ -895,7 +921,7 @@ The [`perf_hooks.performance`][] object.
895
921
added: v0.1.7
896
922
-->
897
923
898
- * Type: {Object}
924
+ - Type: {Object}
899
925
900
926
The process object. See the [ ` process ` object] [ ] section.
901
927
@@ -905,7 +931,7 @@ The process object. See the [`process` object][] section.
905
931
added: v11.0.0
906
932
-->
907
933
908
- * ` callback ` {Function} Function to be queued.
934
+ - ` callback ` {Function} Function to be queued.
909
935
910
936
The ` queueMicrotask() ` method queues a microtask to invoke ` callback ` . If
911
937
` callback ` throws an exception, the [ ` process ` object] [ ] ` 'uncaughtException' `
@@ -1244,7 +1270,7 @@ The WHATWG `URLSearchParams` class. See the [`URLSearchParams`][] section.
1244
1270
added: v8.0.0
1245
1271
-->
1246
1272
1247
- * Type: {Object}
1273
+ - Type: {Object}
1248
1274
1249
1275
The object that acts as the namespace for all W3C
1250
1276
[ WebAssembly] [ webassembly-org ] related functionality. See the
0 commit comments