Showcaselfloyd Showcaselfloyd -4 years ago 112
Node.js Question

What's the second set of parenthese mean after a required statement in Node.js?

I'm working with a coworkers code today and I saw something I've never scene before.

I understand the first part of the statement (require in the file clean.js).

But what's with the second set of parentheses?

require('./tasks/clean')('js', './dist/js')

Answer Source

Whatever is exported from ./tasks/clean is a function, so it's just being invoked with 'js' and './dist/js' as parameters

It is equivalent to the following:

const clean = require('./taks/clean');
clean('js', './dist/js');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download