serve

Reference

serve({ port }: { port: number }): { port: number; hostname: string; server: ReturnType<typeof http.createServer>; }

The serve function is used to start the Node.js server and listen for incoming requests.

Example usage:

In the next example, we use the serve function to start the Node.js server.

import { serve } from "brisa/server/node";

const { server, port, hostname } = serve({
  port: 3001,
});

console.log(
  "Node.js Server ready ๐Ÿฅณ",
  `listening on http://${hostname}:${port}...`,
);

Keep in mind that the serve for Node.js is not in brisa/server but in brisa/server/node.

It only makes sense to use it if you need a custom server for extra things from the serve but if you start the server in the same way as Brisa.

Types

export function serve({ port }: { port: number }): {
  port: number;
  hostname: string;
  server: ReturnType<typeof http.createServer>;
};