eolas/neuron/4e98d18e-1a79-4e78-a4ac-f7e3a2de9887/Module_wrapping_at_runtime.md
2024-10-21 23:11:48 +01:00

672 B

tags
node-js

Module wrapping at runtime in NodeJS

The Module Wrapper Function

When Node runs each of our module files are wrapped within an immediately-invoked function expression that has the following parameters:

(function (exports, require, module, __filename, __dirname))

This is called the module wrapper function

Note that one of these parameters is the module object.

Within any module we can access these parameters: you can think of them as metadata about the module itself. __filename and __dirname are particularly useful when writing to files and modifying directories.