module.exports vs exports in Node.js

前端 未结 23 1255
自闭症患者
自闭症患者 2020-11-22 06:11

I\'ve found the following contract in a Node.js module:

module.exports = exports = nano = function database_module(cfg) {...}

I wonder what

23条回答
  •  感情败类
    2020-11-22 06:57

    From the docs

    The exports variable is available within a module's file-level scope, and is assigned the value of module.exports before the module is evaluated.

    It allows a shortcut, so that module.exports.f = ... can be written more succinctly as exports.f = .... However, be aware that like any variable, if a new value is assigned to exports, it is no longer bound to module.exports:

    It is just a variable pointing to module.exports.

提交回复
热议问题