You need to expose a global utility function that should be accessible across different modules in your Node.js application. How would you leverage the global object to achieve this?

  • global.utility = require('./utility');
  • global.util = require('./utility');
  • global.import('./utility')
  • global.include('./utility')
To expose a global utility function in Node.js, you can use global.utility = require('./utility');. This allows you to require the module once and make it accessible globally across different modules. The other options do not achieve this in the correct way.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *