Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine du Hamel <duhamelantoine1995@gmail.com>2022-03-06 01:43:29 +0300
committerGitHub <noreply@github.com>2022-03-06 01:43:29 +0300
commitde3a86b5531375deb2b5779cfc00deae39a80e6e (patch)
treecdfd14b299c48898deba7851aefa5b94e61da65f /doc/api/tls.md
parent91cc4fa32d98952312b5bc543b4f0cd43246112b (diff)
doc: clarify that some modules don't work when compiled without ssl
PR-URL: https://github.com/nodejs/node/pull/42198 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Mestery <mestery@protonmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'doc/api/tls.md')
-rw-r--r--doc/api/tls.md37
1 files changed, 37 insertions, 0 deletions
diff --git a/doc/api/tls.md b/doc/api/tls.md
index d082ed3c805..ad0f5d013cc 100644
--- a/doc/api/tls.md
+++ b/doc/api/tls.md
@@ -14,6 +14,43 @@ The module can be accessed using:
const tls = require('tls');
```
+## Determining if crypto support is unavailable
+
+It is possible for Node.js to be built without including support for the
+`crypto` module. In such cases, attempting to `import` from `tls` or
+calling `require('tls')` will result in an error being thrown.
+
+When using CommonJS, the error thrown can be caught using try/catch:
+
+<!-- eslint-skip -->
+
+```cjs
+let tls;
+try {
+ tls = require('tls');
+} catch (err) {
+ console.log('tls support is disabled!');
+}
+```
+
+When using the lexical ESM `import` keyword, the error can only be
+caught if a handler for `process.on('uncaughtException')` is registered
+_before_ any attempt to load the module is made (using, for instance,
+a preload module).
+
+When using ESM, if there is a chance that the code may be run on a build
+of Node.js where crypto support is not enabled, consider using the
+`import()` function instead of the lexical `import` keyword:
+
+```mjs
+let tls;
+try {
+ tls = await import('tls');
+} catch (err) {
+ console.log('tls support is disabled!');
+}
+```
+
## TLS/SSL concepts
TLS/SSL is a set of protocols that rely on a public key infrastructure (PKI) to