The `Module` Object

Added in: v0.3.7 It is <Object>. Provides general utility methods when interacting with instances of Module — the module variable often seen in file modules. Accessed via require(‘module’).

module.builtinModules

Added in: v9.3.0. It is <string[]>. A list of the names of all modules provided by Node.js. Can be used to verify if a module is maintained by a third party or not. Note that module in this context isn’t the same object that’s provided by the module wrapper. To access it, require the Module module:

const builtin = require(‘module’).builtinModules;

module.createRequireFromPath(filename)

Added in: v10.12.0

  • filename <string> Filename to be used to construct the relative require function.
  • Returns: <require> Require function

const { createRequireFromPath } = require(‘module’);

const requireUtil = createRequireFromPath(‘../src/utils’);

// require `../src/utils/some-tool`

requireUtil(‘./some-tool’);

Share this post
[social_warfare]
The `module` Object
File Operations

Get industry recognized certification – Contact us

keyboard_arrow_up