Read properties file from local machine using javascript/jquery/angular js/angular - javascript

We have a properties file in local machine (for example, c:/foo/foo.properties).
How to read that properties file to get the content in it using javascript, jquery and angular?

Please provide a solution to read it, only using javascript, jquery
and angular.
It's an urgent requirement.
The answer is: It's an impossible mission. There is no way for you to read a file on a computer using Javascript or anything of its frameworks or libraries, except one: which is NodeJS.

You cannot access a local file using client side script due to security issue you have to use some server-side script like node.js,php etc for that to work.

Related

How can I modify a .JSON file stored on server from client side?

I'm working on a webapp that is currently running on a server, where there are also some .JSON files, which I would like the user to be able to type some information and press enter where it will be stored to the .JSON file.
The webapp is written in HTML, CSS, and vanilla Javascript, there aren't any external libraries being used.
I am already pulling information from the .JSON files to be used in the app using the GET function, and I know I can't directly modify server side files with javascript unless I'm running a Node.js server (which isn't currently an option).
So I believe my only option is to use a server side language such as PHP (which I nothing about), to modify the file. My question is, how can I do this relatively simply? Possibly when a JS function is run to push the change to the file.
Can anyone give me a sliver of example code, or point me in the direction of some simple documentation or tutorial on how to do this, I'm not very adept at server side programming at all, and as this is a simple project just for me, I don't want to dive deep into PHP at the moment.
Thank you in advanced!
So I believe my only option is to use a server side language such as PHP (which I nothing about), to modify the file.
Since you already know JavaScript, I'd revisit why you feel you can't use Node.js server-side. In any case, if you're going ahead with PHP...
To write files, file_put_contents().
To encode JSON, json_encode().
Note that there are other servers out there. You don't have to write your own stuff in PHP. If you don't need any checking on what's being sent, you can probably even modify your web server's config to accept a PUT.

Are external javascript libraries hidden?

So I realize that anyone can view the javascript in-line with HTML running in their browser, so if I use an external js library on my server will its contents be completely hidden?
Another question is are there any cases where it's better to use in-line javascript, like with jQuery or something, or is there really no down side to just using a js library for all of it?
No, there is no way that your javascript will ever be "hidden". Anything that can be run in a browser can be trivially saved and inspected. The best you can do is use an obfuscator.
The downside to using an external file is that it's another request. The upside is that it can be cached independently. For best performance, code that will be used from more than one page should be stored in its own file, and code that is page-specific is better off being stored within the page that uses it.
JavaScript operates on the Browser level, that means that the browser at some point read your JS (external or internal same s.). You can easily conclude from this that if at some point the JS is now registered by the browser, and it's accessible by anyone with a bit more knowledge in web stuff. you'll not be able to hide your JS trickery.
Pus inside your JS a Copyright notice and pray.
Never send sensitive data through the yellow wire.
If you have some extra sensitive strings, encode and compare them on server side - sending them like MD5 or in some SHA model to the server.
Javascript, with the exception of something like node, operates client-side so you can't really use an "external js library" on your server, whatever that means.
Best practices dictate that you should almost always reference your javascript using <script> tags and link to your javascript file using the src attribute.

How can you read, write, and create ".txt" files using Javascript?

I am writing a website and I have a very basic understanding of JavaScript (JS) but a good understanding of HTML and CSS. I want to have an admin part of the website were you can edit the content of the site. I also need help on how to display these text files onto the website using JS. Thank you for your help.
No. You can't. For this you will need backend server software, like PHP.
You can do it with ActiveX objects - http://www.yaldex.com/wjscript/jsfilecreateTextFile.htm - but you're tying yourself to proprietary IE support.
Other than that, you'll need a server-side language such as PHP.
In HTML5 you can operate on local files via the File API (have a look at http://www.html5rocks.com/en/tutorials/file/dndfiles/ for a quick tutorial) but manipulating files on the server using JavaScript on its own is impossible. You need to use AJAX to send a request to a PHP (or some other server-side language) script to do it for you.
Impossible, only server-side languages

Writing to a file

I am extracting content from a web page using JS/JQuery and want to write the data to a comma separated file. I know javascript doesn't really support file io and I'm trying to avoid setting up a local apache server just to process the content to a file. Is there an easier way to do this?
You can have your JS create the file text in a string. Then open a new window and write the string into the new window.
You can write a Mozilla Extension.
PROs:
You can use JS/JQuery on the extension
You can write files on the extension
CONs:
You can only use the application in Firefox (or any other Mozilla based browser).
There is no simple way of doing this. W3C has recently published the first draft of a File API that will make it possible, but it'll be a while until this is through and widely implemented.
Still requires a webserver, but you could build a small one method web service that your js calls, then the service can write out the data.

Edit a file using javascript

I need to edit an xml file using javascript. Now I'm involved in a project of online testing.
The question.xml file is already in the project folder.
In that i want to add or edit the questions(only using javascript). I'm able to bring the particular content through ajax, but I am not able to edit the file.
Javascript can't write to a file. The best you'll be able to do is get Javascript to read and edit the XML then post that data to a server-side script to write to file.
Until now, Google Chrome is the only web browser that has a functioning implementation of the FileSystem API, therefore, it may allow you to save files locally using only Javascript.
Obviously, for security reasons, when writing files to the local file system, the user must explicitly allow it.
A working tutorial: http://www.html5rocks.com/en/tutorials/file/filesystem/
Nickf is correct. The reason Javascript can't write to a file is because it is a Client-Side language. Javascript will never have permission to write a file because it has to operate inside the browser sandbox.
You will need to use a server-side script (.NET, PHP, ColdFusion, etc) to write the file.
If you are willing to use Google Gears, you get a sandbox on the client machine on which you can write files.
Javascript has no built-in file I/O (a.k.a. you can't do it with JS alone)
Instead use some kind of server side language such as PHP or ASP.NET in conjunction with Javascript's AJAX functionality.
Look over Adobe's Flex development system. There are ways you can use it to build an app that runs in the browser (or not) and can access the filesystem (Windows/Mac/Linux). It's programmed in ActionScript, a dialect of javascript; and can interoperate with javascript in the browser.

Categories