Starting the Server
startServer
Signature:
startServer(port?: number): http.Server
Starts the HTTP server and listens on the specified port.
port— Optional. Port number to listen on. Defaults to5000.- Returns the native
http.Serverinstance.
Example:
// Default port (5000)
app.startServer()
// Custom port
app.startServer(3000)
The console will confirm the server is running:
App @ http://localhost:3000
Accessing the Server Instance
startServer returns the native Node.js http.Server, which you can use for advanced scenarios like WebSockets:
import { WebSocketServer } from "ws"
const server = app.startServer(3000)
const wss = new WebSocketServer({ server })
wss.on("connection", (ws) => {
ws.send("Connected!")
})