nikunjkr
nikunjkr

Reputation: 13

How does the require function takes parameter in Node.js with Socket.io

I do not understand what does (http) means here in the following javascript code. If its a method it should have been called after a dot. But its not. So what exactly is it?

var io = require('socket.io')(http)

Upvotes: 1

Views: 46

Answers (1)

CherryDT
CherryDT

Reputation: 29012

It's a function call.

require('socket.io') returns a function. The function is then called with parameter http.

Maybe this makes it clearer, it's the same thing but with an extra variable assignment:

var factoryFunction = require('socket.io')
var io = factoryFunction(http)

Upvotes: 1

Related Questions