ENF News Bot
Automated News Bot
- Joined
- Apr 15, 2022
- Messages
- 2,591
When using a Worker with the
You can use
index.jsjs
index.tsts
Additionally, you can now use other APIs including
Note that
You can use
index.jsjs
index.tsts
All
You can use
This includes
index.jsjs
index.tsts
Continue reading...
nodejs_compat compatibility flag enabled, you can now use the following Node.js APIs:node:net
https://developers.cloudflare.com/changelog/rss/#nodenetYou can use
node:net ↗︎ to create a direct connection to servers via a TCP sockets with net.Socket ↗︎.index.jsjs
Code:
import net from "node:net";
const exampleIP = "127.0.0.1";
export default {
async fetch(req) {
const socket = new net.Socket();
socket.connect(4000, exampleIP, function () {
console.log("Connected");
});
socket.write("Hello, Server!");
socket.end();
return new Response("Wrote to server", { status: 200 });
},
};
Code:
import net from "node:net";
const exampleIP = "127.0.0.1";
export default {
async fetch(req): Promise<Response> {
const socket = new net.Socket();
socket.connect(4000, exampleIP, function () {
console.log("Connected");
});
socket.write("Hello, Server!");
socket.end();
return new Response("Wrote to server", { status: 200 });
},
} satisfies ExportedHandler;
Additionally, you can now use other APIs including
net.BlockList ↗︎ and net.SocketAddress ↗︎.Note that
net.Server ↗︎ is not supported.node:dns
https://developers.cloudflare.com/changelog/rss/#nodednsYou can use
node:dns ↗︎ for name resolution via DNS over HTTPS using Cloudflare DNS ↗︎ at 1.1.1.1.index.jsjs
Code:
import dns from "node:dns";
let response = await dns.promises.resolve4("cloudflare.com", "NS");
Code:
import dns from 'node:dns';
let response = await dns.promises.resolve4('cloudflare.com', 'NS');
All
node:dns functions are available, except lookup, lookupService, and resolve which throw "Not implemented" errors when called.node:timers
https://developers.cloudflare.com/changelog/rss/#nodetimersYou can use
node:timers ↗︎ to schedule functions to be called at some future period of time.This includes
setTimeout ↗︎ for calling a function after a delay, setInterval ↗︎ for calling a function repeatedly, and setImmediate ↗︎ for calling a function in the next iteration of the event loop.index.jsjs
Code:
import timers from "node:timers";
console.log("first");
timers.setTimeout(() => {
console.log("last");
}, 10);
timers.setTimeout(() => {
console.log("next");
});
Code:
import timers from "node:timers";
console.log("first");
timers.setTimeout(() => {
console.log("last");
}, 10);
timers.setTimeout(() => {
console.log("next");
});
Continue reading...