Advanced Endpoints
The --listen
(or -l
) flag is a powerful feature that allows serve
to listen on more than just a simple TCP port. You can specify one or more endpoints, including TCP ports, UNIX domain sockets, and Windows named pipes.
This flexibility is useful for inter-process communication or integrating serve
into complex development and testing environments.
Specifying Endpoints
Endpoints are specified as URIs. Here are the supported formats:
TCP Port
For listening on a specific TCP port on all available network interfaces. This is the most common use case.
- Format: A simple number.
-
Example:
# Listen on port 5000 serve -l 5000
TCP Host and Port
For listening on a specific network interface and port.
- Format:
tcp://<hostname>:<port>
-
Example:
# Listen only on the localhost interface on port 8080 serve -l tcp://localhost:8080 # Listen on a specific network IP serve -l tcp://192.168.1.10:3000
UNIX Domain Sockets
For listening on a UNIX domain socket, which is a file on the filesystem used for inter-process communication on POSIX-compliant systems (like Linux and macOS).
- Format:
unix:/path/to/socket.sock
-
Example:
serve -l unix:/tmp/my-app.sock
Windows Named Pipes
For listening on a Windows named pipe, the equivalent of UNIX sockets on the Windows operating system.
- Format:
pipe:\\.\pipe\<PipeName>
-
Example:
serve -l pipe:\\.\pipe\my-app-pipe
Listening on Multiple Endpoints
You can specify the --listen
or -l
flag multiple times to make serve
listen on several endpoints at once. This is useful for exposing your server in different ways simultaneously.
# Listen on port 3000 for network access
# AND on a UNIX socket for local process communication
serve -l 3000 -l unix:/var/run/my-app.sock