Skip to main content


Deno standard library
Go to Latest
function createServer
import { createServer } from "";

Creates a new TCP or IPC server.

Accepts an options object with properties allowHalfOpen (default false) and pauseOnConnect (default false).

If allowHalfOpen is set to false, then the socket will automatically end the writable side when the readable side ends.

If allowHalfOpen is set to true, when the other end of the socket signals the end of transmission, the server will only send back the end of transmission when socket.end() is explicitly called. For example, in the context of TCP, when a FIN packed is received, a FIN packed is sent back only when socket.end() is explicitly called. Until then the connection is half-closed (non-readable but still writable). See "end" event and RFC 1122 (section for more information.

pauseOnConnect indicates whether the socket should be paused on incoming connections.

If pauseOnConnect is set to true, then the socket associated with each incoming connection will be paused, and no data will be read from its handle. This allows connections to be passed between processes without any data being read by the original process. To begin reading data from a paused socket, call socket.resume().

The server can be a TCP server or an IPC server, depending on what it listen() to.

Here is an example of an TCP echo server which listens for connections on port 8124:

import { createRequire } from "";
import { Socket } from "";

const require = createRequire(import.meta.url);
const net = require("net");

const server = net.createServer((c: Socket) => {
  // "connection" listener.
  console.log("client connected");
  c.on("end", () => {
    console.log("client disconnected");

server.on("error", (err: Error) => {
  throw err;

server.listen(8124, () => {
  console.log("server bound");

Test this by using telnet:

$ telnet localhost 8124


options: ServerOptions

Socket options.

connectionListener: ConnectionListener

Automatically set as a listener for the "connection" event.


A net.Server.