File tree Expand file tree Collapse file tree 3 files changed +109
-0
lines changed Expand file tree Collapse file tree 3 files changed +109
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,41 @@ can be accessed using:
2828const http2 = require (' http2' );
2929```
3030
31+ ## Determining if crypto support is unavailable
32+
33+ It is possible for Node.js to be built without including support for the
34+ ` crypto ` module. In such cases, attempting to ` import ` from ` http2 ` or
35+ calling ` require('http2') ` will result in an error being thrown.
36+
37+ When using CommonJS, the error thrown can be caught using try/catch:
38+
39+ ``` cjs
40+ let http2;
41+ try {
42+ http2 = require (' http2' );
43+ } catch (err) {
44+ console .log (' http2 support is disabled!' );
45+ }
46+ ```
47+
48+ When using the lexical ESM ` import ` keyword, the error can only be
49+ caught if a handler for ` process.on('uncaughtException') ` is registered
50+ _ before_ any attempt to load the module is made (using, for instance,
51+ a preload module).
52+
53+ When using ESM, if there is a chance that the code may be run on a build
54+ of Node.js where crypto support is not enabled, consider using the
55+ ` import() ` function instead of the lexical ` import ` keyword:
56+
57+ ``` mjs
58+ let http2;
59+ try {
60+ http2 = await import (' http2' );
61+ } catch (err) {
62+ console .log (' http2 support is disabled!' );
63+ }
64+ ```
65+
3166## Core API
3267
3368The Core API provides a low-level interface designed specifically around
Original file line number Diff line number Diff line change 99HTTPS is the HTTP protocol over TLS/SSL. In Node.js this is implemented as a
1010separate module.
1111
12+ ## Determining if crypto support is unavailable
13+
14+ It is possible for Node.js to be built without including support for the
15+ ` crypto ` module. In such cases, attempting to ` import ` from ` https ` or
16+ calling ` require('https') ` will result in an error being thrown.
17+
18+ When using CommonJS, the error thrown can be caught using try/catch:
19+
20+ <!-- eslint-skip -->
21+
22+ ``` cjs
23+ let https;
24+ try {
25+ https = require (' https' );
26+ } catch (err) {
27+ console .log (' https support is disabled!' );
28+ }
29+ ```
30+
31+ When using the lexical ESM ` import ` keyword, the error can only be
32+ caught if a handler for ` process.on('uncaughtException') ` is registered
33+ _ before_ any attempt to load the module is made (using, for instance,
34+ a preload module).
35+
36+ When using ESM, if there is a chance that the code may be run on a build
37+ of Node.js where crypto support is not enabled, consider using the
38+ ` import() ` function instead of the lexical ` import ` keyword:
39+
40+ ``` mjs
41+ let https;
42+ try {
43+ https = await import (' https' );
44+ } catch (err) {
45+ console .log (' https support is disabled!' );
46+ }
47+ ```
48+
1249## Class: ` https.Agent `
1350
1451<!-- YAML
Original file line number Diff line number Diff line change @@ -14,6 +14,43 @@ The module can be accessed using:
1414const tls = require (' tls' );
1515```
1616
17+ ## Determining if crypto support is unavailable
18+
19+ It is possible for Node.js to be built without including support for the
20+ ` crypto ` module. In such cases, attempting to ` import ` from ` tls ` or
21+ calling ` require('tls') ` will result in an error being thrown.
22+
23+ When using CommonJS, the error thrown can be caught using try/catch:
24+
25+ <!-- eslint-skip -->
26+
27+ ``` cjs
28+ let tls;
29+ try {
30+ tls = require (' tls' );
31+ } catch (err) {
32+ console .log (' tls support is disabled!' );
33+ }
34+ ```
35+
36+ When using the lexical ESM ` import ` keyword, the error can only be
37+ caught if a handler for ` process.on('uncaughtException') ` is registered
38+ _ before_ any attempt to load the module is made (using, for instance,
39+ a preload module).
40+
41+ When using ESM, if there is a chance that the code may be run on a build
42+ of Node.js where crypto support is not enabled, consider using the
43+ ` import() ` function instead of the lexical ` import ` keyword:
44+
45+ ``` mjs
46+ let tls;
47+ try {
48+ tls = await import (' tls' );
49+ } catch (err) {
50+ console .log (' tls support is disabled!' );
51+ }
52+ ```
53+
1754## TLS/SSL concepts
1855
1956TLS/SSL is a set of protocols that rely on a public key infrastructure (PKI) to
You can’t perform that action at this time.
0 commit comments