Skip to main content

Function: serve()

serve(options): Server

Start an HTTP server.

const server = tjs.serve({
fetch(request) {
return new Response('Hello World!');
},
port: 8080,
});

A shorthand is also available when only a fetch handler is needed:

const server = tjs.serve((request) => new Response('Hello!'));

Parameters

options

Server options or a fetch handler function.

ServeOptions | FetchHandler

Returns

Server

The server instance.