I have director structure like this, only $(Root Directory)'s name is known at run time.
other folders and files are generated dynamically.(All files are .json)
my requirement is I need to count no of files and read content of all files using jquery and ajax.
I know if we have some static path like abc/xyz/somefile.json then we can read someFile.json but in my case I need to traverse nested folders.
help
You will not be able to do it without server-side support, either from the web server itself or another server-side process.
If directory listing is enabled on your web server, you can make an ajax request directly to the directory you want and scrape the returned document's content.
Another way would be to setup a web service which allows to query a directory's content. That service would be responsible for querying the file system and return the information to the client in a data-interchange format like JSON.
Related
i have written a game in javascript with the p5.js library. Now i want to host the game on a server to conduct a survey on a service like amazon turk. Ideally the clients recieve a URL to the game and play it while in-game actions are tracked and stored in node.js or on the server and exported as a .csv file once they are done playing. After they finish the game the csv. file should be sent automatically to a location that i can then access. I have zero experience in server hosting or similar topics.
So a couple questions arise:
Is a hosting service like Heroku suitable for hosting the game?
Do i need to use node.js to make this happen?
Which of those two would extract the data and store it to a csv? And where is the file stored?
How do i get or access the csv. after?
Any alternative takes to solve the problem?
Thanks alot in advance!
github repository: https://github.com/luuuucaaa/schaeffers-charade
game on github pages: https://luuuucaaa.github.io/schaeffers-charade/
If I were you, I would do it like below:
Host
Since your project is basically a html & JavaScript static contents,
AWS S3's static hosting would be sufficient (Also, the current git hub pages is another option if you just want to host it).
Hosting on node.js environment is also available using webpack serving, but it requires additional works. (but if you require other npm packages to generate .csv file, you need webpack anyway to bundle js file and attach it to html)
Data Storing
Two ways are considerable,
the first is to store it on the filesystem. Generate .csv via JS script within your app, and save it where the app is hosted (if you go with s3, you can access it afterwards, but I'm not sure if it can write objects by script)
The second is to post the data to another API endpoint. (for example building an API Gateway on AWS that triggers Lambda, which stores it on S3)
It's merely an example and I don't know exactly what you want to achieve, but take it into considerations. Good luck. Cool game BTW.
So i have set up a basic nodejs server using express and everything works fine. I have a json file in my folder that i want to be able to modify, to add some data or remove some.
What is the best way to do that without the user being able to interact with the actual file? Perhaps a database that i could send my data to?
I am very new to nodejs and javascript so anything that is as simple as possible is the best.
You could create different http routes for setting and fetching data in the json file.
Say, for example:
GET /data would read the json file and respond with the contents of the file.
POST /data could post the contents of the file.
PUT /data/key could be used to modify the contents of one single key in the json.
That being said, this looks like something that you should be using a DB for. If somewhere down the line, you choose to dockerize your app, everytime you restart your server, your JSON file would be reset to the initial config.
To avoid that, a db could be used. Mongo is a good place to start considering your choice of language and nature of your data.
Hope you find this helpful :)
I have a server-side subfolder structure in my HTML5/JS site.
The subfolder structure contains various media types where each media file is wrapped in its own HTML file which contains metatags.
I want to list all metatags for all files but I do not want to have to browse for a file (i.e. no FileSystem API) and get it's metadata. I just want to scan through the subfolder and list all metadata in each file.
I'm not able to find any script to do this, everything I keep running into is asking for the FileSystem API and the requirement to browse for a file.
alternatively, if FileSystem API can do this, I'd use it as long as I don't have to go browsing for files to use it.
My server is a standard LAMP server and the files are all HTML files inside a site subfolder. This site currently has no DB and I'm hoping to not add one for this functionality.
Any help would be appreciated.
Maybe Node.js would be a good fit for you. Then you can write everything in Javascript. It is server side scripting, but for demonstration purposes the configuration is much easier than Apache.
If I understand correctly that you don't want to browse the file system on the server side, but on the client side you are willing to do anything with Javascript, then the following may also be an option.
Using LAMP, you can configure Apache so that it shows directory indexes (https://httpd.apache.org/docs/current/mod/mod_dir.html#directoryindex), which you can use to browse to the content you need on the client side.
In any case, you will have to hit the files on your server somehow, either directly through the file system on the server side or with an HTTP request from the client side.
How can I get list of filenames from a specified folder through javascript?
Assuming the folder you're talking about is on the client, then you can't. It'd bring up all sorts of security issues if JavaScript had that power.
If the folder is on the server then you could use some form of AJAX, with the server side code fetching the files in the specified directory and returning it back to the client.
I am trying to write a small documentation tool to be used from the browser. It would need to fetch source code files from a web server. What would be the appropriate way to fetch files from JavaScript itself and then read them so they can be parsed ? The file to be fetched is on a different web server.
thanks in advance,
vivekian
Use some sort of ajax framework (or XmlHttpRequest) that would read a file, parse it and display it.
You'll have to create a proxy to that other server. Otherwise you're going to run into security exceptions.
Given your main url http://www.x.com/help.html, and the source files that are located at http://www.x321.com/src/, you're going to create a proxy at http://www.x.com/proxy/ to http://www.x321.com/src/