O'Reilly logo

Hands-On Microservices with Node.js by Diogo Resende

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Modules

You develop Node.js code in separate files, called modules. There are three module types:

  • Core modules, which you can load anywhere
  • Dependency modules, which you can also load anywhere
  • Local modules, which you need to load based on the relative path

Modules are loaded synchronously and cached. So, a repeated load will actually not be a load; instead, Node.js will pass you a reference to the already loaded module. This is true for all three types of modules:

# loading a JSON file with settings from same path as moduleconst settings = require("./settings");

Local modules are simple files where you need to know the relative or full path. You can also load a path and Node.js will look up the index.js file inside it. You can also load ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required