And what about:
var myModule = require.main.require('./path/to/module');
It requires the file as if it were required from the main js file, so it works pretty well as long as your main js file is at the root of your project… and that’s something I appreciate.
More Related Contents:
- How to deal with cyclic dependencies in Node.js
- The difference between “require(x)” and “import x”
- How to remove module after “require” in node.js?
- What is the difference between require(‘mypackage.js’) and require(‘mypackage’)?
- Detect if called through require or directly by command line
- How does require work with new operator in node.js?
- How can I make Node.js ‘require’ absolute? (instead of relative)
- NodeJS require a global module/package
- What is the fastest way to write a lot of documents to Firestore?
- NodeJS write base64 image-file
- CRUD blueprint overriding in sails.js
- Node Sass does not yet support your current environment: Linux 64-bit with false
- socket.io rooms or namespacing?
- Next.js: How to get static assets from within getStaticProps
- How to set limit for array size in Mongoose schema
- Enable Access-Control-Allow-Origin for multiple domains in Node.js [duplicate]
- Use docker run command to pass arguments to CMD in Dockerfile
- Zip archives in node.js
- MongooseError – Operation `users.findOne()` buffering timed out after 10000ms
- Microsoft Bot framework: Sending Message on connect
- npm install -g less does not work: EACCES: permission denied
- Mongoose nested query on Model by field of its referenced model
- Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (88)
- ENOENT: no such file or directory .?
- How to wait for a child process to finish in Node.js
- Unable to Change Favicon with Express.js
- npm install that requires node-gyp fails on Windows
- npm update check failed
- Mongoose overwrite the document rather that `$set` fields
- How to access Google Chrome’s IndexedDB/LevelDB files?