Home » Node.js Net

Node.js Net

Node.js provides the ability to perform socket programming. We can create chat application or communicate client and server applications using socket programming in Node.js. The Node.js net module contains functions for creating both servers and clients.

Node.js Net Example

In this example, we are using two command prompts:

  • Node.js command prompt for server.
  • Window’s default command prompt for client.

server:

File: net_server.js

Open Node.js command prompt and run the following code:

Node.js net example 1

client:

File: net_client.js

Open Node.js command prompt and run the following code:

Node.js net example 2

Note: You must match the port. The client and server should have similar port for successful connection.

Next TopicNode.js Crypto

You may also like