SHARE
TWEET

Untitled

a guest Oct 13th, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Nodejs Require Module Resolution
  2.  
  3. ```javascript
  4. // ./main.js
  5. require('./example-module').whoami();
  6.  
  7. // ./example-module.js
  8. module.exports.whoami = () => console.log(`Hello, I'm a file`);
  9. // Output: ./example-module.js
  10.  
  11. // ./example-module/index.js
  12. module.exports.whoami = () => console.log(`Hello, I'm an index.js file inside a directory`);
  13. // Output: ./example-module/index.js
  14. ```
  15.  
  16. Executing the main.js file described above will output `Hello, I'm a file` as the file `example-module.js` is given precendence over a directory of the same name, when the `require` module attempts to resolve `./example-module`.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top