Node.js has a ‘net’ module which provides an asynchronous network API for creating stream-based TCP/IPC servers and clients.

It can be accessed using:

const net = require('net');  

To create a TCP/IPC based server, we use the  createServer method.

var server = net.createServer(); 

The ‘server’ object is of type  net.Server. Let’s explore a few properties, events and methods on this class.

First and foremost, the method needed is ‘listen’ which starts the server for listening to connections in async, firing the ‘listening’ event.

server.listen(9000, () => { 
  console.log('opened server on port: ', 9000); 
}); 

#node #node.js

What is Node.js Net Module?
1.70 GEEK