I was reading the documentation from the net module in Node.js and I can't see any difference between the methods net.connect
and net.createConnection
.
Are they exactly the same or is there is some difference?
I was reading the documentation from the net module in Node.js and I can't see any difference between the methods net.connect
and net.createConnection
.
Are they exactly the same or is there is some difference?
Share Improve this question edited Sep 9, 2016 at 10:24 Denys Séguret 382k90 gold badges810 silver badges775 bronze badges asked Sep 9, 2016 at 9:42 Valentin BarralValentin Barral 1334 bronze badges 02 Answers
Reset to default 14There's no difference. Here's an extract from the source code:
exports.connect = exports.createConnection = function() {
I agree the documentation isn't clear on that point.
The are exactly the same, just a different name, form the sourced code
net.createConnection() creates a net.Socket object and immediately calls net.Socket.connect() on it.
And also from the source code on line 62 of the Net module.
exports.connect = exports.createConnection = function() {
stuff
};
Why they did this, I don't know. Just pick the naming convention that you prefer and off you go :)