What is the Meteor server-side path to /public?

落花浮王杯 提交于 2019-12-01 04:41:26

When I use the fs-module I just use './public' for my public folder, works fine on my local install.

And then I set it to whatever's correct at the production server using environment vars.

Edit (an example):

This method will return all .HTML files from the public folder:

getHtmlFilesInPublicFolder: function() {

    var files = fs.readdirSync('./public/');

    var cleanedUpFiles = _(files).reject( function(fileName) {
        return fileName.indexOf('.html') < 0;
    });

    return cleanedUpFiles;

}

The accepted "./public/" answer does not work for me in Meteor 1.1.

However, Meteor supplies the server path via the meteor_bootstrap.serverDir variable, so to get the public folder path I use the following line:

path.join(__meteor_bootstrap__.serverDir, "../web.browser/app");

This works on my local Windows machine and on meteor.com.

Note that this is the "running" version of your public folder, so - at least in development, I haven't checked this part in production - it's actually a merge of your development "public" folder and all of your client-side JS files. If you have a "config" folder in your project, and a "config" folder in your public directory, the "running" path will include the contents of both.

there's an upgrade since the 0.6.5 version of meteor, main.js now chdirs into programs/server in your bundle. So the content of the public directory is here : ../client/app/

the detail on github

If you are using nodes file system library on the client then you are going to be working with your local file system structure and you're files will be referenced by the local path to where ever they reside on your local disk.

For example.. if your project is located at /home/bob/meteor_projects/project1 then your files are located at /home/bob/meteor_projects/project1/public

Abk

I got the absolute path for Meteor project directory using below line of code.

var absPath = process.env.PWD;

I have used this with Meteor 1.4.3.2 and it works perfectly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!