Following operations are going to take place :
A text file is created using a java program and it gets stored in a folder
The file needs to be read and displayed in the text box which is present in the browser UI.
For this to happen, the java script needs to check the folder till the text file becomes available and then read it and display it in the text box.
How will the javascript come to know when the text file is available in the folder and how is it going to read it and display it.
We are using Nodejs as the container and Ember Java for the web framework
This is only possible if you run Ember locally rather than served from a web server.
Create an in-repo addon in your Ember app. It will have Node context.
Have the addon watch the folder for changes. Read the file when it's available
Have the addon run a web server that responds with file contents when it's available.
Configure your app for long polling the web server.
If you do need to server the app from a web server, then you're out of luck. You can try running a desktop app on the computer that watches the folder for changes then sends the file contents to the server. Then the app can request the file from the server. That's more elaborate.
Related
Currently, I'm working on a web-based configuration tool for a domain-specific language (DSL) implemented with Xtext. In the previous process, users configure devices using an XML file, which can be messy and often error-prone. Using the new DSL approach enables the automatic compilation of those XML files.
Since Xtext offers Web Editor support, I decided to go this route to prevent the installation of an additional application for the configuration process. The Servlet for the Xtext backend runs locally. Now here is my issue:
The user can either open an existing configuration or create a new one with the DSL editor and save it as a file to a specific path on the PC. Now I'd like to compile the result to the source file's location without the user having to navigate there. For this, the Xtext backend would need the exact location of the saved/opened file, but as the editor is running as a web application, I can't get the absolute path to the file due to security reasons.
The compile process works with a workaround by passing the config file content as text to the backend. The Xtext backend then returns the result to the web application as text, so now I'm asking, is there a way to save the result as a file in the same path as the initially loaded file?
I created a prototype about a tool that would analyze source code and write metadata about it in files to be read by a web application served locally.
Now I need to specify details about how I'll implement it. The data would need to go both ways, first the backend write to file and the frontend read from file, second the frontend write to file and backend read from file.
My question is about how I do the second part, saving from the browser to local files, knowing that I will be serving the page locally.
I've found this api https://web.dev/native-file-system/ that might be what I need, but it's pretty new and requires permission from the user. I guess I can do it differently because I'll serve it locally.
For more context, here's the video of my prototype
I'd like to use html+css+js to create an interface for setting up a simulation. The interface is used to create a visualisation of the simulation, and an output parameters file, by using several input files.
This web-page does NOT need to run on a server and is only run locally on the same machine.
I understand why a sever page is not allowed to access a client file, and that a server page may access another server file. Is it possible for a LOCAL web-page to access a local file?
It is possible to view the contents of any file using file:///path/to/file.txt so I presume that it is somehow possible to pull the result into a running page in the form of a string. However I'm having very little success.
If it is possible please could you detail a simple example of how the contents of a txt file could be read into a string?
Thank you very much
node.js is a javascript implementation that can easily do such things because it is a process running on the machine. A web page is running in a browser which does not have access to the file system, so that would not be possible, however you could bundle your web application into an electron application which would be able to access the osand file system, so while it would use html and javascript it would still require an installation.
If you are using Chrome, you can launch it with the --allow-file-access-from-files flag. Then you can do:
fetch('file:///path/to/file.txt')
.then(function(response) {
// do something with it
})
I am trying to build a simple website with just an index file and a folder full of icons for our internal purpose. I am making this so that anyone in our team can just access the link and download the icons whenever needed without our help. I am trying to read the icons file name from the folder automatically, so every time we update the folder with new ones we don't have to edit the HTML. I know only JavaScript. Please help me.
An alternative could be to produce a filelist of the files via a script or batch file (depending on OS, something like - in psudeo - ls path/to/images > filelist.txt) which redirect the output to a file that ends up in the same root as the index and images.
This file could then be read via fetch() or XMLHttpRequest() and parsed on client side to provide the basis for the links to the updates files.
This would require an extra step in the pipe-line of course, but could easily be automated using a listener for the image directory that triggers the script, part of your project setup and so forth.
This is not possible. In your case Javascript is running in the browser (client-side). It has no access to the servers filesystem. You need a server-side dynamic web-service (php, node.js, ...)
I have developed some touchscreen content that will be run on a local machine at an event. It will be run full screen using Chrome, and I need to load various html content dynamically into a container. Is this possible, as the usual JQuery load() and ajax methods only seem to work when running off of a server. All the content sits in its own folder as a html file, so I just need to point to the correct html file as and when needed.
Is there a way to do this when all content is being run locally?
It sounds like you're not running an http server. You can't get ajax from the file:// protocol. You need to run a local http server.
If your backend language is javascript, you should run nodejs
If your backend is php you should probably run apache2