Skip to content

Checks whether Node.js is running a global module.

License

Notifications You must be signed in to change notification settings

gagle/node-is-global

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

is-global

Checks whether Node.js is running a global module

NPM version

NPM installation

There are times that you need to know whether Node.js is executing a global module, typically when you're writing a third-party module and want to execute different pieces of code depending on the current context; local or global module.

On Windows the PATH environment variable is read to check the context. Node.js scripts running inside the npm install directory will always return true, eg:

cd C:\Users\<user>\AppData\Roaming\npm
node app.js

Therefore, don't run scripts from inside the npm install directory. No one does that so you can assume that on Windows platform it detects the global module execution correctly.

Functions


module() : Boolean

Returns true if Node.js is executing a global module, otherwise false.

var isGlobal = require ("is-global");
if (isGlobal ()){
  ...
}else{
  ...
}

About

Checks whether Node.js is running a global module.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published