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.
Loading...
Related Quiz
- You are maintaining a library, and you need to release a new version that fixes a bug but also changes the behavior of an existing feature. How should you update the version number according to semantic versioning?
- You are developing a media hosting platform where users can upload images and videos. How would you design the file storage and retrieval system to ensure high availability and low latency for users across the globe?
- What is the primary role of the app object in an Express application
-
Developers can use npm deprecate
[@ ] to mark a package or a specific version as deprecated, displaying a warning message ______ to any developers installing it. - How can you send JSON data as a response using the http module in Node.js?