Tuesday, 2 May 2017

Sharing variables across node modules

I have a main module (app.js) which initializes a client (for making REST api calls) and have functions in that main module that use this client. As my code is growing bigger, I'd like to modularize my main by putting the functions into modules (say module_A.js). What is the best practice to have this client initialized and shared across the various modules? One way I thought about is to create a client module which I require in each modules - would the client not be initialized multiple times then? Christian



via Christian68

No comments:

Post a Comment