A basic CommonJS module loader in the style of the default Node.js module loader. It resolves dependencies in your code, and then executes it using the vm module in Node.js.
This is an example project, and is NOT meant to be used in production code. I wrote this to help myself understand how the Node.js module loader works under the hood. Just sharing it in case it helps others too.
Project setup:
yarn install
yarn link
Require using require
:
require("./path/to/file.js")
Export using module.exports
or exports
:
module.exports = {...}
// or
exports.something = ...
Execute your file using the CLI:
cjs-loader <path-to-file>