What Local Databases are avaliable for Javascript? - javascript

I'm developing a project in Server Side Javascript (SJS) using POW webserver. The result of the project will be a local application for users that will interact with a sort of "Database" of Answers and Questions (It's like a Quiz Builder).
Actually we are just starting and we are storing informations into JSON files (POW allows read/write of plain files), but I'm looking for a more efficient way to store and recall information from the DB (something SLQ-like).
Is there any possibility of doing this using Javascript? One of the requirements is that the user doesn't have to install a DB server (Mysql, Sqlite ecc) so it should be a Javascript-pure way, or even XML-HTML5 way (I'm not going to use WebDB or similars).

There are two client-side database features in modern browsers: IndexedDB and Web SQL.
Neither is fully supported across the current versions of the various browsers, but IndexedDB seems to be the one which is going to win -- the Web SQL is apparently no longer being maintained, and may be dropped entirely.
You can find out more about them both, and their respective browser support on the CanIUse website.
[EDIT] As mentioned by #Raynos, there is also LocalStorage, which actually appears to have much better cross-browser support than either of the other two mentioned above. Given the browser support (even IE8 supports it!), this would seem to be the best option for the time being, even though it isn't as fully featured as the other options above.
Here's the CanIUse details for LocalStorage.
Hope that helps.

POW provides simple access to SQLite DB, saved in pow/data folder.
http://davidkellogg.com/wiki/Pow_db

Related

How to test chat web app

I am developing chat application, using node.js socket.io module on a server, and javascript on a client. As it become more complex, I become tired to test different usage scenarios by clicking across browsers. At now I use different browsers in order to separate cookies. So in Firefox there is one chat participant, in Opera - second, etc.
Therefore my question is:
Can I automate this somehow?
I've heard about headless testing engines like Phantom JS, Selenium WebDriver, but I don't know how to write tests between different browsers. In fact, I indeed need to separate cookies, different browsers are here only for this task.
May be I cannot explain my problem to Google :) All answers on such question imply cross-browser development, and testing that aspect.
Any help will be appreciated a lot!
The answers shown at How to test two interacting browsers (e.g. chat app) might be of use if you try to go the Casper/Phantom/SlimerJS route. I'm not marking it as a duplicate as your question is more general, whereas that one is about exactly how to synchronize two CasperJS instances; it is also not specifically about socket.io.
Note: if using Phantom to test Web Sockets you will need to get Phantom 2.x (which is still experimental, and does not have an easily downloadable beta yet), as Phantom 1.x uses an old WebKit. SlimerJs always uses a recent Gecko (i.e. Firefox) engine, so is fine.
Each instance of PhantomJS can have its own cookies. This answer (and the other answer on that question) explains your choices well.
SlimerJS cookies are similar, but persistent cookies are stored in the Mozilla profile, so if you wanted to run multiple instances, you would want to specify an explicit profile for each instance. (Though your chat application may only be using session cookies, in which case this does not matter.)
Anyway, as cookies are used I would definitely run two instances of CasperJS, rather than try to use two tabs, or two frames.

JavaScript to read local file

Is there any way to enable native JavaScript to read local file on the disk?
no Ajax, no JQuery or other JavaScript library, only use the native JavaScript?
I have searched, but it seems there is no way to do this.
My requirements are that when the Internet can not be accessed, I will show a warning page in the Chrome browser.
HTML5, have a File Api, if you are interested in reading file, just for the reading - MSDN, HTML5rocks.
If you are more interested in the case when the user is offline, and your application needs a storage, you can take a look at localstorage - MDN, diveintohtml5. There is an example how to check if it is available, although CanIUse says it is currently available everywhere. Here is a live example.
Hope this will help, in your case which seems to be the synchronization after being offline.
If you are using JavaScript in a browser, there is no way to access an arbitrary file from the local filesystem like this. XMLHTTPRequest can be used to access files natively without a library like jQuery, but it prevents access to local files as a security measure.
However, you can use a cache.manifest file to set up an offline version of an HTML 5 site/app.
You can use a combination of <input type="file"/> and Javascript's window.FileReader to read file. It has many methods of receiving the data, easiest being FileReader.readAsBinaryString(file); You can only read files that a user has selected from a file browser.
Here's Mozilla Developer Network's documentation on it.
For your uses, however, it seems like developing a Chrome extension would be a better solution to manipulating the way Google Chrome works.

Javascript client-side what databases are available excluding browser specific ones

Trying to determine what actual non-browser (HTML 5) specific databases that are available for use in JavaScript client-side programing. I do not want to use activeX controls.
If you are looking for a NoSQL-style db on the client you can check out http://www.forerunnerdb.com. It supports the same query language as MongoDB and has a data-binding module if you want your DOM to reflect changes to your data automatically.
It is also open source, is constantly being updated with new features and the community around it is growing rapidly.
Disclaimer, I'm the lead developer of the project.
Initially the W3C created Web SQL, but that is no longer active. The current flavour is the Indexed Database API, which is a stand alone specification but requires support for DOM 3 Events, HTML5, WebIDL and WebWorkers.
Recent browsers should provide some support, however I don't think it's all that complete and certainly not ubiquitous. If you are targetting popular mobile devices or recent desktop browsers, you may be OK.

How can I analyze a file about to be uploaded before it's actually uploaded?

We are currently planning a website on which people can upload movies. When looking at YouTube you notice that some movies are uploaded twice or more times (by different users). To scale our application we're thinking about the following idea:
User selects movie file to be uploaded
A JavaScript will get the SHA256 hash from the file (it's more accurate then the MD5 hash) before it get's uploaded
The website will check if the hash already exists
If the hash doesn't exist, the file will be uploaded
If the hash does exist a message will be prompted or a reference to the already existing version on the server will be created. This without the video being uploaded.
Q: How do we analyze a file with JavaScript in order to get the SHA256 hash, and is SHA256 good enough or should we consider SHA512 (or another algorithm)?
Use the HTML5 File API to read the file: http://www.html5rocks.com/en/tutorials/file/dndfiles. Here is a JS code for calculating SHA-256: http://www.webtoolkit.info/javascript-sha256.html
I must add that I never tried this, but it seems to be possible. Alxandr is right, this would take very long for large videos, but you may try to use the WebWorker API in order not to freeze the browser: http://html5rocks.com/en/tutorials/workers/basics
Putting files aside for now, if the question is actually whether it's possible to get a SHA-256 hashes in JavaScript, the answer is yes. You can either reiplement this yourself (bad idea) or use a library like the Stanford JS Crypto library (good idea).
As far as the File API goes, it is implemented in the bleeding edge version of every major desktop browser, as well as the latest Android browser shipping. iOS is not supported as it doesn't really have a filesystem. Check out caniuse.com for the latest stats.
Simple answer, you can't. That is if you want to support all browsers at least. I think both Chrome and FireFox supports the reading of files on the client, and IE supports it with the help of ActiveX controls, but to get a solution that works in all browsers you have to use a plugin like Flash or Silverlight. Also, when doing file-uploads of video-magnitude (large+ files), I think going for flash or the likes from the start is a good idea anyhow, but that's just my opinion.

Desktop application in Javascript/CSS/HTML for Google Chrome

I have to make a Google Chrome based application solely for desktop purpose. By Desktop I meant that it would not be loaded from some URL rather would be invoked on the machine only. The data would be stored/fetched from HTML5 SQLite databases or some storage provided by CHrome(Is there any?) The application would be purely based on Javascript/CSS/HTML. I also have to make it secure so that nobody could "steal" the code and data.
Can you refer me some relevant documents?
Thanks
You might want to consider making a Chrome plugin instead. As rcapote already mentioned, you can't really make JS secure in the way you want (even with an obfuscator). However, IF you can lock down your environment sufficiently, a Chrome plunging will be a lot more secure.
To be really safe though, as much as I hate to say it, you should really switch to a compiled format instead. There are even JS compilers (that compile to other languages).

Categories

Resources