Get application full path in Node.js -


i'm wondering if there best way or best practice full path of application in node.js. example: have a module in sub folder /apps/myapp/data/models/mymodel.js, , full path of app (not full path of file), return me /apps/myapp, how do that? know _dirname or _file relative file not full path of app.

there's better solution, but should work:

var path = require('path');  // find first module loaded var topmodule = module;  while(topmodule.parent)   topmodule = topmodule.parent;  var appdir = path.dirname(topmodule.filename); console.log(appdir); 

edit: andreas proposed better solution in comments:

path.dirname(require.main.filename) 

edit: solution nam nguyen

path.dirname(process.mainmodule.filename) 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -