On the Meteor client-side, I know that files in the project's public directory are referenced at '/'.
How are they referenced on the server-side?
I am trying to get a directory listing with fs.readdir, but I don't know how to construct the path to get to the server side equivalent of the client side '/images/gallery'.
Any advice?
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
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.
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;
}
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
Related
I want to apply this deno.json configuration file to all my deno projects:
{
"fmt": {
"options": {
"indentWidth": 4
}
}
}
Is there a way to globally apply this configuration so I don't have to have this deno.json file in every project?
I'm using VSCode, Ubuntu and Deno 1.28.1.
Because of the way that the Deno VS Code extension overrides/suppresses the built-in TS language server, it is not advised to enable the extension globally: this would cause problems in every non-Deno TypeScript project.
That said, you can create a single deno.json(c) file at a high-level location in your filesystem — for example: in your home directory. To use a concrete example location — on Linux — /home/your_username/deno.json.
Then, when configuring a new VS Code project, you only need to configure the location of the config file in .vscode/settings.json in order for the extension to use it:
{
"deno.enable": true,
"deno.config": "/home/your_username/deno.json"
}
When using Deno in the CLI, it will automatically walk your filesystem and find the nearest parent config file. From the manual:
Since v1.18,
Deno will automatically detect deno.json or deno.jsonc configuration file if
it's in your current working directory (or parent directories).
Regardless of the above, this strategy is not advised: a better approach might be to simply to create a personal CLI script/function which will generate a new deno config and VS Code config from a template that you create. This way, each of your projects maintains its own configuration data (a good thing) and you also don't have to manually configure each new one because you did the work once to create the template generation script (win-win).
I have an ASP.NET 5 project with a plenty of Node.js modules. They are installed under the node_modules folder.
In the development environment (environment=development), I started copying all the modules to wwwroot\lib manually. When that became tedious, I wrote a Gulp task to copy them. Now there are plenty of tasks.
Is there any ASP.NET project setting so the modules can be loaded from the node_modules folder at the root rather than from the wwwroot\lib?
Edit: For development purposes, just add one more UseStaticFiles middleware. To your Startup.cs -> public void Configure() method -> Add this:
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), #"node_modules")),
RequestPath = new PathString("/node_modules")
});
UseStaticFiles is used twice. First, to serve static files from a default wwwroot and the second time to serve /node_modules files. As described here.
Just be careful in production environment.
There should be a package.json file in the same directory with that node_modules, you only need to copy it to the new location then run npm install from the command-line to install the packages. Then the new modules will soon be available at the new location.
I'm trying to read a .json file in /public folder. Relative path I'm using is '../../../../../public/data.json' and it works when I run with meteor run.
However, when I deploy to meteor subdomain by running meteor deploy MyApp.meteor.com, it crashes and the logs say
Error: ENOENT, no such file or directory '../../../../../public/data.json'
I tried using 'data.json', 'public/data.json', etc. but I couldn't get it to work. What am I missing here?
Put the data in a "private" directory off of your app root instead of "public" (assuming that you're only going to read it on the server, which is what you seem to be doing). When you want the file (regardless of if you are deployed or not), it is at the path "assets/app/".
For example, if your app had the directory structure:
myApp.css
myApp.js
myApp.html
server/
serverCode.js
private/
data.json
You could use something like "peerlibrary:fs", which exposes fiber aware fs sync functions, and do the following in "serverCode.js"
var data = JSON.parse(fs.readFileSync("assets/app/data.json"));
If you put the file data.json in the root of the public folder you can just use the path "/data.json"
im trying to install PhantomJS in a MeteorApp.
I have done those step:
Add the npm package
meteor add meteorhacks:npm
Run meteor to let the npm package to pre-initialise
meteor
A file packages.json has been created at the root. Edit it to:
{
"phantomjs": "1.9.13"
}
A this point everything seem to work. But i try to test with this exemple that ive found here :
https://github.com/gadicc/meteor-phantomjs
But i dont understand where to put my phantomDriver.js
Why is phantomDriver.js is in assets/app/phantomDriver.js... but after, they say to create the file in ./private/phantomDriver.js...
Thank for clear explication :)
In development mode you create the file in /private/phantomDriver.js. When you build a meteor app it refactors everything into an application bundle which can be run.
After meteor builds your app it stores stuff from private into assets. For phantomjs to execute this file it needs to look in this directory. You don't have to create it. This is how meteor works internally.
If you look in your .meteor/local/build/programs/server directory the assets directory is there with anything you placed in private.
From the context of where your meteor code runs (the server directory above) the assets directory runs from this directory when your project is running.
Keep in mind when you deploy your app it loses its entire project structure and becomes something else. Gadi's phantomjs project is designed to work in production environments too.
TLDR; Don't worry about the assets directory, keep your file in /private/phantomDriver.js. Meteor should take care of the rest.
I am trying to get deploy root directory of my servlet based project from java. I am using the following lines of codes to get the path details.
Type 1:
File directory = new File (".");
try {
System.out.println ("Current directory's canonical path: "
+ directory.getCanonicalPath());
System.out.println ("Current directory's absolute path: "
+ directory.getAbsolutePath());
}catch(Exception e) {
System.out.println("Exceptione is ="+e.getMessage());
}
Type 2:
String currentDir = System.getProperty("user.dir");
System.out.println("Current dir using System:" +currentDir);
While executing the above codes from main class i am getting user directory. When i executes from server side, gets as, "Current dir using System:D:\Apache Tomcat 6.0.16\bin". But my project is located in D:\Apache Tomcat 6.0.16\wepapps\SampleStructs.
Please give me any suggestions for this and help me out of this.
First of all, the main cause of your problem is the difference between current working directory and the location of your executable. You should know that current working directory in Linux is not the directory where the executable is, but instead the current directory where the program was started from.
As an example, let's say you have a program current which prints out the current directory and it is located in /home/user/scripts/.
If you do this:
cd /home/user/scripts
./current
It will print out: /home/user/scripts/
But, if you do this:
cd /home/user/
scripts/current
The output will be: /home/user/
As to the possible solutions, some of them I found useful are:
Refer to your project resources relative to the classpath, see ClassLoader.getResourceAsStream() for more info
Refer to your configuration resources, like properties files and such, relative to the user home directory.
Put all other locations, such as media directory path and similar to the configuration file from the point above.
If all other options are not available or practical use getClass().getProtectionDomain().getCodeSource().getLocation().getPath(). See more about this approach and some possible issues here: How to get the path of a running JAR file?
It because when you execute from main class everything is fine, but this code runs on server it looks into current directory and current the directory structure is Apache 'bin' from where you have started the server(run.bat).
you can use this code
String absolutePath = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
absolutePath = absolutePath.substring(0, absolutePath.lastIndexOf("/"));
this code is working before for me!
it will return the full path of folder in windows or linux.
There are different context we are talking about here.
1. Running the application in standalone mode.
2. Running the application in container on server side.
In #1, The application is run from the directory it is invoked.
But #2 case, the application is run relative to the container, so you see the location of server directory. This also shields the application code.