Browser-based JS database [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed last month.
Improve this question
I'm working on a little side project and wanted to keep it as simple as possible.
So app will have no back end, it will just be a single html page with some local javascript included that can be passed around and run locally.
Given those requirements, I'm looking for a some sort of solution that would let me store and load data like you would a database, in a way the data can be permanently stored in a file. So preferably, being able to use a json file like a NoSQL database.
I've looked at lowdb, alasql, and lokijs, but none of those seem to meet my requirements. They either need a node server to function, or only use local storage or memory to store data.

You can't (except with an ugly workaround).
Such an application would require JavaScript to read/write from disk while running inside a webpage in a browser, and it's not technically possible. This has nothing to do with the file format.
However...
The workaround is to keep all the data in a JSON file, then load it dinamically via JavaScript (for example, with drag and drop). Then when you need to save it... you allow the modified JSON to be downloaded, and once downloaded you'd replace the old JSON with this new one, manually.

Related

Where to host javascript Closed Source front-end library for distribution? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I have a JavaScript library I would like to distribute to clients for using through script tag on their websites.
My project is not open-source so I cannot use open-source services like jsDelivr.
I was thinking about using Firebase (I hope they have good CDN) hosting where I would upload my script, which will be then directly accessed by other websites. Is this a viable solution or is there other/better service for this use-case?
Firebase Hosting has no access control on deployed files. That means that, like on any public CDN, anyone who knows the URL of the file can access it.
If you don't want to share the code publicly, you should probably not put the file on any CDN. Distributing the code directly to your customers would be the most logical alternative. They would then include the code directly into their build process, instead of pulling it live from the CDN.
But if you want to pull it from the CDN, the best you can do is use an unguessable URL. Typically something very long and random like http://mycdn.com/path/to/file/unguessableFDJIQRE(##(U/index.js. This ensure that random users are unlikely to ever find the file, and only users who know if its existence can get it. That said, here too it remains that anyone who knows the URL of the file can access it.
There are a few strategies here:
Uglify/minimize your JS script. Users will still be able to read it, but it will be hard because all of the variable names will be replaced with not human readable names. That said, it's definitely possible to reverse engineer an uglified script.
Use a JS obfuscator, which will go a step further and rewrite your code to be almost indecipherable.
Set up a static webserver that requires an authentication token to serve up your script. Unless your clients pass a valid auth header, they'll get a 404.

Have the HTML File Selector browse server side [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I am trying to get the HTML file selector <input type="file"> to browse files that are on my server, instead of local. I know JS is client side, and I tried researching various implementations but no one seems to have something on this. I would prefer an implementation that doesn't require downloading any external application (I already have jQuery and ajax).
edit: I don't know why I'm getting down voted! I'm not trying to get Javascript to list files I feed from the server, I'm trying to explore the servers files and directories like I was physically on it from the "file" api.
There is no way to get the HTML file-selector <input type="file"> to browse files that are on your server.
However, you can set up a workaround using a little server-side programming. Create an API route on the server that sends the structure of files that are on your server in response (maybe in the form of a JSON object or an array) and use that to show the file structure to the user.

Best way to query or search through a CSV from HTML website [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I am wondering what the best way would be to search or query through a csv that will be in the same directory as an HTML site I am writing. There is a search bar where a user can put the name of someone into, when they click search I'd like there to be an Alert popping up showing some information from that csv matching the name they entered.
I've looked for a few examples in Javascript and php. I'm having trouble wrapping my head around them tho. Does anyone have a fairly simple script that would accomplish what I'm looking for?
Thanks!
You have several options. Most obvious ones are:
1- In JS, you can use built-in CSV parsing function in D3JS:
http://bl.ocks.org/enjalot/1525346
2- In JS, you can use built-in jQuery.get() or jQuery.ajax() function in jQuery:
http://api.jquery.com/jQuery.get/
3- In JS, you can use $http service in Angular:
https://docs.angularjs.org/api/ng/service/$http
4- In Php, you can use fgetcsv() function:
http://php.net/manual/en/function.fgetcsv.php
5- In Php/JS, you can convert your file to JSON and upload it to Backend as a service platform such as Firebase and query it from your app via API calls.
https://firebase.google.com/docs/reference/rest/database/
If having the whole csv on the client side is not an issue, then on page load, I would read the csv through PHP and keep the data in a javascript variable so it essentially becomes a client side search (super fast search).
If you should not have the csv data on the client side, then write a webservice in PHP to read the csv (or, pre read using some other script and store the full csv as an array using php memcached which is in memory store) and then your web service can just search the in-memory array which will also be a little fast than reading the full csv every time your search.

Language Recommendation: Easiest approach for displaying csv data in a graph on the intranet (not internet) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I've done a fair bit of coding, but haven't really done anything with the browser. I have a python script that will be running on a chron job that will auto-generate .csv output files, somewhere on a network drive. I'd like to have an intranet browser display some sort of page where users on the network would be able to choose from drop-down menus to choose what .csv data will be displayed as a graph.I was thinking of using chart.js to handle the graphs.
So, to summarize:
I have many .csv files that will be auto-generated every couple of days on a network drive that many users have access to.
I'd like to create an internal browser-based display of the data.
I'm considering using php for this, but was unsure if there is a better choice.
My code for the php/HTML/javascript/whatever I use, needs to:
Read in the .csv files
Take user input via dropdown menus to see what data the user wants to see.
Display the data with something like chart.js, though I'm not sure what Javascript can play nicely with when it comes to these things.
My initial thought is to use a php page that embeds HTML and Javascript in it, but since I've never did any sort of browser-based coding, I'd be open to the opinion of anyone with more experience. Thanks!
Option 1)
Convert CSV to JSON in a php file (Convert CSV to JSON using PHP), use AJAX to transfer that data to your HTML page, then use chart js to display the data once you have it. Using html dropdown menus, the values selected on these menus can be used as parameters in your ajax calls, so your php code can use those parameters to determine what CSV to load.
Option 2)
Keep the CSV format, and use that data directly in libraries like C3js (here are examples http://c3js.org/samples/data_load.html). You can then use JS and your HTML dropdown to determine what file to grab.

Create a new html file using JavaScript [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I want to be able to create a new html file that will be displayed and saved on the server for future use when a new user logs into their account. Can this be done using JavaScript or are there any libraries that I could get that would be able to do this?
This can be done through use of the fs module in node. See https://nodejs.org/api/fs.html.
However, it is very likely that this is not the best solution to the problem your solving. Instead of creating a new html file for every user, you probably want to save user details in a database and have a single html file that can be populated with the data when it's needed.
This is not possible with JavaScript alone unless you use Node.js. Otherwise will need PHP or a similar server-side language.
If you go that route, here is a nice tutorial that may be beneficial to you:
http://tutorialzine.com/2011/05/generating-files-javascript-php/

Categories