In Node.JS, requiring ('net'), you do not require ("event")?

The code I'm looking for does not have "require (" event ")" anywhere ", and yet I see this code

server.on('error', function (e) { if (e.code == 'EADDRINUSE') { console.log('Address in use, retrying...'); setTimeout(function () { //server.close(); server.listen(port);//PORT, HOST); }, 1000); } else{ ....... 

Uses "on".

And looking at this line

 var net = require('net') 

and this line

 var server = net.createServer(); 

makes me think that the execution of require ('net') already includes the execution of require ('event').

Is it correct?

+5
source share
1 answer

The documentation clearly states that net.Server is an EventEmitter , so the properties and methods of EventEmitter (including .on() ) are inherited.

+4
source

Source: https://habr.com/ru/post/1237302/


All Articles