The net module

The net module in Node.js allows us to create network connections. The connections that are created will be streams that we can write to and read from. This section will focus on just network connections and not HTTP. Node.js has a full HTTP module, and we will cover that in the next section.

All the functions assume that the net module has been loaded like this:

var net = require('net');

createServer

This function will create a TCP server:

net.createServer([options], [listener]) 

Return value

This returns a net.Server object.

Description

This function allows us to listen for connections. The returned object will be a net.Server object, and the connection listener will be passed to a net.Socket object. We will cover both of these objects ...

Get Web Developer's Reference Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.