Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor project path from a smartpackage

Tags:

node.js

meteor

I was looking for a way to look up the meteor project path from a smart package (e.g.: obtain the path of the directory where the .meteor folder is ...). I was not able to do it using node's __dirname and __filename because somehow in meteor they are not avaiable. Any tips ?

like image 277
Roberto Avatar asked Oct 22 '12 19:10

Roberto


3 Answers

As of Meteor 0.6.0 this would be:

var path = Npm.require('path');
var basepath = path.resolve('.');
like image 119
emgee Avatar answered Nov 09 '22 06:11

emgee


From a smartpackage (0.6.5+):

var path = Npm.require('path');
var base = path.resolve('.');

base in this case gets you the position of your package ..

/User/username/projects/project/.meteor/local/programm/server/...

.. might even be deeper

but we want

/User/username/projects/project/

.. so split at .meteor

base = base.split('.meteor')[0];


Or as two-liner

var path = Npm.require('path');
var base = path.resolve('.').split('.meteor')[0];;
like image 31
nooitaf Avatar answered Nov 09 '22 07:11

nooitaf


This works for me in Meteor 0.5.0:

var require = __meteor_bootstrap__.require;
var path = require('path');
var basepath = (path.resolve('.'));
like image 26
Josh Wulf Avatar answered Nov 09 '22 06:11

Josh Wulf