Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including magic-globals with all npm packages installed. Try it out:

var magicGlobals = require("magic-globals")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

magic-globals v0.9.1

Magic Globals, ex. `__line` and `__func`. Similar to Magic Constants in PHP

Magic Globals

Similar to Magic Constants in PHP. Useful for debugging.

npm version gluten


// require this module without assigning export

// you may now use additional global objects,
// in addition to built-ins: __filename and __dirname
console.log(__filename) // /home/node/myapp/server/server.js
console.log(__file) // server
console.log(__line) // 6
console.log(__fili) // /home/node/myapp/server/server.js:6
console.log(__ext) // js
console.log(__base) // /home/node/myapp
console.log(__func) // someFunction or (anonymous) 
console.log(__dirname) // /home/node/myapp/server


These sources have helped to create this module by sharing their code:



These are alternative projects which can yield achieve a similar result:



(The MIT License) Copyright (c) 2015 Gavin Engel <>


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free