Skip to content

Latest commit

 

History

History

README.md

Node.js HTTP Server Template for Cloudflare Workers

Deploy to Cloudflare

A simple Node.js HTTP server template using the built-in node:http module, designed to run on Cloudflare Workers.

Quick Start

  1. Install dependencies:

    npm install
  2. Run locally:

    npm run dev
  3. Deploy to Cloudflare Workers:

    npx wrangler deploy

Usage

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 });

Configuration

The wrangler.toml includes the necessary compatibility flags:

compatibility_flags = ["nodejs_compat"]
compatibility_date = "2025-09-03"

Scripts

  • npm start - Start the server
  • npm run dev - Start with hot reload
  • npm test - Run tests

Learn More

License

MIT