module.exports vs exports in Node.js

前端 未结 23 1639
自闭症患者
自闭症患者 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:51

    I found this link useful to answer the above question.

    http://timnew.me/blog/2012/04/20/exports-vs-module-exports-in-node-js/

    To add to the other posts The module system in node does

    var exports = module.exports 
    

    before executing your code. So when you want to exports = foo , you probably want to do module.exports = exports = foo but using exports.foo = foo should be fine

提交回复
热议问题