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 inbrisa/server
but inbrisa/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>;
};