Function serve

  • Start a fast HTTP server.

    Example

    Bun.serve({
    fetch(req: Request): Response | Promise<Response> {
    return new Response("Hello World!");
    },

    // Optional port number - the default value is 3000
    port: process.env.PORT || 3000,
    });

    Example

    Send a file

    Bun.serve({
    fetch(req: Request): Response | Promise<Response> {
    return new Response(Bun.file("./package.json"));
    },

    // Optional port number - the default value is 3000
    port: process.env.PORT || 3000,
    });

    Parameters

    • options: Serve

      Server options (port defaults to $PORT || 8080)


    Returns Server

  • Start a fast HTTP server.

    Example

    Bun.serve({
    fetch(req: Request): Response | Promise<Response> {
    return new Response("Hello World!");
    },

    // Optional port number - the default value is 3000
    port: process.env.PORT || 3000,
    });

    Example

    Send a file

    Bun.serve({
    fetch(req: Request): Response | Promise<Response> {
    return new Response(Bun.file("./package.json"));
    },

    // Optional port number - the default value is 3000
    port: process.env.PORT || 3000,
    });

    Parameters

    • options: Serve

      Server options (port defaults to $PORT || 8080)


    Returns Server

Generated using TypeDoc