Skip to content

Instantly share code, notes, and snippets.

@arieljannai
Created May 22, 2016 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arieljannai/1145e967879bb285a267ab4f5dfc9b44 to your computer and use it in GitHub Desktop.
Save arieljannai/1145e967879bb285a267ab4f5dfc9b44 to your computer and use it in GitHub Desktop.
Get the base directory of your node module (no matter how deep it is)
var p = require('path');
var f = __dirname.substring(0, __dirname.lastIndexOf('node_modules') + 'node_modules'.length + p.sep.length);
var l = p.relative(f, __dirname);
console.log(l.split(p.sep)[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment