Skip to main content

Posts

Showing posts with the label package

module.exports vs exports

One of the most powerful things about software development is the ability to reuse and build upon the foundations of other people. This code sharing has helped software progress at an amazing rate. Such a wonderful mechanism is critical on a micro-level for both individual projects and teams. For Node.js, this process of code sharing – both within individual projects and in external npm dependencies – is facilitated using  module.exports  or  exports . How Node Modules Work How do we use module exports to plug an external module, or sensibly break our project down into multiple files (modules)? The Node.js module system was created because its designers didn't want it to suffer from the same problem of broken global scope, like its browser counterpart. They implemented  CommonJS specification  to achieve this. The two important pieces of the puzzle are  module.exports  and the  require  function. How module.exports works module.exports  ...