Last active
April 3, 2023 10:56
-
-
Save gavinengel/8572856 to your computer and use it in GitHub Desktop.
"Magic Globals" for node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sets globals: | |
// __stack, | |
// __line, | |
// __file, | |
// __function, | |
// __ext, | |
// __base | |
// we already have these: | |
// __filename which gives as an example: /Users/mjr/example.js | |
// __dirname which gives as an example: /Users/mjr | |
// copied and tweaked from: | |
// http://goo.gl/wwjGVV | |
// http://goo.gl/umq4s1 | |
// https://gist.github.com/branneman/8048520 | |
// https://gist.github.com/lordvlad/ec81834ddff73aaa1ab0 | |
// for __get and __set check out: https://www.npmjs.com/package/magic | |
// TODO: __method and __class ? | |
// npm install magic-globals --save | |
require('magic-globals'); | |
/* | |
console.log('__line: ' + __line); | |
console.log('__file: ' + __file); | |
console.log('__ext: ' + __ext); | |
console.log('__base: ' + __base); | |
console.log('__filename: ' + __filename); | |
console.log('__dirname: ' + __dirname); | |
console.log('__function: ' + __function); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is absolutely useful information for people who use node.js. Node.js has similar stuff like #Perl.