Skip to content
This repository has been archived by the owner on Aug 21, 2021. It is now read-only.
/ node-globals Public archive

immutable namespaced globals for node, main and worker threads

License

Notifications You must be signed in to change notification settings

noahehall/node-globals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Globals!

  • immutable namespaced globals for isomoprhic and progressive web applications
  • Constants management and logic for node, client, and worker threads

why are we here?

  • dont you hate importing and requiring your constants and lib functions all over the friggin place?
    • include namespaced constants and functions one time:
      • on the server, e.g. server.js
      • in the main client thread, e.g. client.js
      • in worker thread, e.g. rootWorker.js
    • on the client main thread: window.appFuncs.somefunction (or just appFuncs.blah)
    • on the client worker thread: self.appConsts.someconst (or just appConsts.blah)
    • in node: global.appFuncs.someFunc (or just appFuncs)

Including globals

  • at the top of the appropriate file:
  const setGlobals = require('node-globals').default;
  setGlobals({});
  // or setGlobals({ constants: {...} }) // add or override default constants
  // or setGlobals({ functions: {...} }) // add or override default functions
  // or setGlobals({ constants: {...}, functions: {...} })
  • or without creating a variable, merging process.env variables within your constants, and storing your constants in a some/directory/config.js
  require('node-globals').default({
    constants: Object.assign(
      { nodeOnline: process.env.NODE_ONLINE === 'true' }, require('../config.js').constants
    )
  });

thank me later...

About

immutable namespaced globals for node, main and worker threads

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published