preston
preston

Reputation: 4367

Understanding Meteor JS File Structure and Accessing ALL Folders

I am using NPM (Node.js) to try and traverse ALL of the folders in my Meteor project. However, with my node.js code, I can only seem to access these folders in Meteor: 1.) server 2.) lib 3.) private

I cannot find: 1.) client 2.) public 3.) other folders I added just to the project just to experiment.

The code I use to list the directories are in a .js file inside the server method. Here is the code I used:

var fs = Npm.require('fs');
var dir = './';
var files = fs.readdirSync(dir);

and I get the following printed to the console:

I20141208-15:18:24.272(8)? [ 'app',
I20141208-15:18:24.272(8)?   'assets',
I20141208-15:18:24.273(8)?   'boot.js',
I20141208-15:18:24.273(8)?   'config.json',
I20141208-15:18:24.273(8)?   'node_modules',
I20141208-15:18:24.273(8)?   'npm',
I20141208-15:18:24.273(8)?   'npm-shrinkwrap.json',
I20141208-15:18:24.273(8)?   'package.json',
I20141208-15:18:24.273(8)?   'packages',
I20141208-15:18:24.273(8)?   'program.json',
I20141208-15:18:24.274(8)?   'start.sh' ]

How can I access the client folder, public folder, etc.??? After all, these folders and the files inside are ultimately in the 'server' too but maybe in a different level. Thank you very much for your help.

Upvotes: 2

Views: 754

Answers (2)

saimeunt
saimeunt

Reputation: 22696

The current working directory of a Node.JS process Meteor app is :

.meteor/local/build/programs/server

The content of your client-side app will be located at :

.meteor/local/build/programs/web.browser/app

If you want to access this folder in server-side Node you'll need to do something like :

var clientFilesDir=process.cwd()+"/../web.browser/app";
var clientFiles=fs.readdirSync(clientFilesDir);

Upvotes: 3

You could get the root directory through the PWD environment variable. Reading environment variables in Meteor is done through the process.env object. I'm not sure how this works in windows, though.

  var fs = Npm.require('fs');
  var dir = process.env.PWD;
  var files = fs.readdirSync(dir);

Upvotes: 1

Related Questions