TCP Server



examples/net/tcp-server.js
const net = require('net');

const server = net.createServer(function(socket) {
    socket.write('hello\n');
    socket.end('world\n');
});

server.listen(8000);

node examples/net/tcp-server.js


$ telnet localhost 8000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
hello
world
Connection closed by foreign host.