'Node JS: net.Socket is not a constructor
The below code works fine if I run it from my command line, but if I run this code anywhere in my project I get this error:
net.Socket is not a constructor
I've tried making the below code an object and importing / requiring it into my project and I still get that error.
var net = require('net');
var client = new net.Socket();
client.connect(3000, '127.0.0.1', function() {
console.log('Connected');
client.write('Hello, server! Love, Client.');
});
Am I miss understanding what require does, I also tried using import and import * as to obtain 'net'.
I'm not too sure what information would be useful in the situation. Any suggestions would be great.
Solution 1:[1]
use node 16 version. these features are currently under Node.js v16.9.1 https://nodejs.org/dist/latest-v16.x/docs/api/net.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sandeep chand |
