A simple Node.js HTTP server template using the built-in node:http module, designed to run on Cloudflare Workers.
-
Install dependencies:
npm install
-
Run locally:
npm run dev
-
Deploy to Cloudflare Workers:
npx wrangler deploy
The template creates a basic HTTP server:
import { createServer } from "node:http";
import { httpServerHandler } from "cloudflare:node";
const server = createServer((req, res) => {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("Hello from Node.js HTTP server!");
});
server.listen(8080);
export default httpServerHandler({ port: 8080 });The wrangler.toml includes the necessary compatibility flags:
compatibility_flags = ["nodejs_compat"]
compatibility_date = "2025-09-03"npm start- Start the servernpm run dev- Start with hot reloadnpm test- Run tests
MIT