Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 253 Vote(s) - 3.57 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find absolute base path of the project directory

#1
Until now we could get the absolute path of a file to open later as readStream with this code snippet:

var base = path.resolve('.');
var file = base + '/data/test.csv';

fs.createReadStream(file)

Since Meteor 0.6.5 the base path is pointing to `.meteor/local/build/programs/...`

There is also the Assets API, which but can not give us back a path but only the read document. We but need a stream to process some bigger data files?
Reply

#2
I ran into the same predicament when I updated to 0.6.5.

What I'm currently doing is getting the path like this:

var meteor_root = Npm.require('fs').realpathSync( process.cwd() + '/../' );

This returns **on dev mode**:

/my/application/.meteor/local/build/programs

and **on bundled mode**:

/my/application/build/app/programs

So from here I'm getting to my application's "root" path like so:

var application_root = Npm.require('fs').realpathSync( meteor_root + '/../' );

// if running on dev mode
if( Npm.require('path').basename( Npm.require('fs').realpathSync( meteor_root + '/../../../' ) ) == '.meteor' ){
application_root = Npm.require('fs').realpathSync( meteor_root + '/../../../../' );
}

The only case in which this would fail is if you happen to name your application's folder ".meteor" but that's an edge case.

Relative to that you can access whatever else you need to.


Additionally, you can also get direct access to to the assets folder that the meteor bundler creates:

var assets_folder = meteor_root + '/server/assets/' + Npm.require('path').basename( application_root );



This is likely to be temporary as I expect better file/path interaction APIs to be added eventually..

Hope that helps
Reply

#3
For Meteor 0.8.3,

`__meteor_bootstrap__.serverDir` gives out the working directory, when run in server mode.

example

if (Meteor.isServer) {
console.log(__meteor_bootstrap__.serverDir);
}
Reply

#4
Hey you do not need to hardcode like the above answers... take a look to [This package][1]

After install it you can access the root path of your meteor just wih `Meteor.rootPath`


[1]:

[To see links please register here]

Reply

#5
Another way to find your project's root directory now is this:

var base = process.env.PWD

Note that this is not the same as `process.cwd()`. Instead it is the directory where you ran the `meteor` command, which is typically what you are looking for. Note also that this probably won't be very helpful when running your app from a deployed bundle.
Reply

#6
As of Meteor 1.2.1, this works for me:

var absoluteBasePath = path.resolve('../../../../../.');

The same result using `split`:

var absoluteBasePath = path.resolve('.').split(path.sep + '.meteor')[0];

Using `process.cwd()`:

var absoluteBasePath = path.resolve(process.cwd(), '../../../../../');
var absoluteBasePath = path.resolve(process.cwd()).split(path.sep + '.meteor')[0];
Reply

#7
Since version 1.3, the [documented][2] function

`Assets.absoluteFilePath(assetPath)`

seems to be the best way to get the project path reliably.

[Meteor Github][1]


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#8
you could get project basic root path by

process.env.PWD
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through