Skip to content

Commit ce3dc8d

Browse files
committed
Updates to docs
1 parent 13510cd commit ce3dc8d

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

src/content/changelog/workers/2025-04-08-nodejs-compat-updates.mdx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Node.js APIs from the node:crypto and node:tls modules are now avai
44
products:
55
- workers
66
date: 2025-04-08T14:00:00Z
7-
hidden: true
7+
# hidden: true
88
---
99

1010
import { Render, PackageManagers, TypeScriptExample } from "~/components";
@@ -24,10 +24,10 @@ The full [`node:crypto`](https://nodejs.org/api/crypto.html) API is now availabl
2424
You can use it to verify and sign data:
2525

2626
```js
27-
import { sign, verify } from 'node:crypto';
27+
import { sign, verify } from "node:crypto";
2828

29-
const signature = sign('sha256', 'some data to sign', env.PRIVATE_KEY);
30-
console.log(verify('sha256', 'some data to sign', env.PUBLIC_KEY, signature);
29+
const signature = sign("sha256", "-data to sign-", env.PRIVATE_KEY);
30+
const verified = verify("sha256", "-data to sign-", env.PUBLIC_KEY, signature);
3131
```
3232

3333
Or, to encrypt and decrypt data:
@@ -58,12 +58,17 @@ import { connect } from "node:tls";
5858
// ... in a request handler ...
5959
const connectionOptions = { key: env.KEY, cert: env.CERT };
6060
const socket = connect(url, connectionOptions, () => {
61-
console.log(
62-
"client connected",
63-
socket.authorized ? "authorized" : "unauthorized",
64-
);
65-
stdin.pipe(socket);
66-
stdin.resume();
61+
if (socket.authorized) {
62+
console.log("Connection authorized");
63+
}
64+
});
65+
66+
socket.on("data", (data) => {
67+
console.log(data);
68+
});
69+
70+
socket.on("end", () => {
71+
console.log("server ends connection");
6772
});
6873
```
6974

src/content/docs/workers/runtime-apis/nodejs/tls.mdx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,20 @@ external services using [TLS](https://developer.mozilla.org/en-US/docs/Web/Secur
1313
```js
1414
import { connect } from "node:tls";
1515

16-
const connectionOptions = { key: env.KEY, cert: env.CERT };
17-
1816
// ... in a request handler ...
17+
const connectionOptions = { key: env.KEY, cert: env.CERT };
1918
const socket = connect(url, connectionOptions, () => {
20-
console.log(
21-
"client connected",
22-
socket.authorized ? "authorized" : "unauthorized",
23-
);
24-
stdin.pipe(socket);
25-
stdin.resume();
19+
if (socket.authorized) {
20+
console.log("Connection authorized");
21+
}
22+
});
23+
24+
socket.on("data", (data) => {
25+
console.log(data);
26+
});
27+
28+
socket.on("end", () => {
29+
console.log("server ends connection");
2630
});
2731
```
2832

0 commit comments

Comments
 (0)