Can javascript write to a file?

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

39 Replies - 35514 Views - Last Post: 16 April 2014 - 08:15 PM

#1 EdNolan  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 411
  • Joined: 22-September 13

Can javascript write to a file?

Posted 20 December 2013 - 04:28 PM

I have a tough question and hope I ask it clear enough to get the right answer. Let me ask it by using an example. Lets say I have a javascript form to get data from the client side. Instead of using *.cgi, phpMySQ or a *.pl file, can a javascript file be used to actually write to another file?

Here's what I think I want to do. LOL. I want the information submitted to to go to a text style database, delimited I guess. 1 record would be returned from the database to the user, every so many seconds. One column in the database would have to be updated every time something is displayed.

Can javascript do this? Or do I have to use *.cgi, *.pl, phpMySQL?

Is This A Good Question/Topic? 0
  • +

Replies To: Can javascript write to a file?

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9579
  • View blog
  • Posts: 36,290
  • Joined: 12-June 08

Re: Can javascript write to a file?

Posted 20 December 2013 - 04:58 PM

.. like this?

http://nodejs.org/do...est/api/fs.html
Was This Post Helpful? 1
  • +
  • -

#3 EdNolan  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 411
  • Joined: 22-September 13

Re: Can javascript write to a file?

Posted 20 December 2013 - 05:05 PM

Wow, thanks that was fast. I think this is it. If javascript can write to files then why do people still want to use PHP MYSQL?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9579
  • View blog
  • Posts: 36,290
  • Joined: 12-June 08

Re: Can javascript write to a file?

Posted 20 December 2013 - 05:11 PM

Honestly I wouldn't write to a local client file for much, but instead write to a db.. so.. I would lean php..
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10816
  • View blog
  • Posts: 40,315
  • Joined: 27-December 08

Re: Can javascript write to a file?

Posted 20 December 2013 - 05:13 PM

*
POPULAR

Node.js is a server-side technology, *not* a client side technology as you are used to using. So the client (ie., the user's machine) still sends data to the server. The server (on which you have Node.js installed) handles the processing of said data. PHP is another technology one can use to handle server-side processing, as are Java EE, ASP.NET, and ColdFusion.

MySQL is a database engine. There are lots of reasons to use MySQL over writing to a file. It makes organizing data more clear, and it allows for easier lookup as well. There is a lot of relational database theory and practice behind MySQL that is difficult to reproduce simply by using text files.
Was This Post Helpful? 7
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6110
  • View blog
  • Posts: 23,670
  • Joined: 23-August 08

Re: Can javascript write to a file?

Posted 21 December 2013 - 04:20 AM

Local Storage for Web Applications
Was This Post Helpful? 1
  • +
  • -

#7 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 451
  • View blog
  • Posts: 1,946
  • Joined: 30-April 10

Re: Can javascript write to a file?

Posted 21 December 2013 - 11:04 AM

If you use local storage remember that it can only take a string. if you want to save multiple items you will need to use an array and then use JSON.stringify

Then before use you will use JSON.parse to make it into an object that you can then get properties from.

This post has been edited by laytonsdad: 21 December 2013 - 11:05 AM

Was This Post Helpful? 0
  • +
  • -

#8 EdNolan  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 411
  • Joined: 22-September 13

Re: Can javascript write to a file?

Posted 21 December 2013 - 03:10 PM

Looks like Node.Js is what I was looking for. Lots of reading to do now. Thanks everyone for the input.
Was This Post Helpful? 0
  • +
  • -

#9 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1428
  • View blog
  • Posts: 3,171
  • Joined: 05-April 11

Re: Can javascript write to a file?

Posted 22 December 2013 - 07:21 AM

View PostEdNolan, on 21 December 2013 - 10:10 PM, said:

Looks like Node.Js is what I was looking for. Lots of reading to do now. Thanks everyone for the input.

I seriously doubt node.js is what you are looking for :S
Was This Post Helpful? 1
  • +
  • -

#10 EdNolan  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 411
  • Joined: 22-September 13

Re: Can javascript write to a file?

Posted 22 December 2013 - 11:19 AM

I watched some video's and been reading about node.js and I have a question. All I do is create a seperate *.js file, a *.txt file, call the *.js to execute right?

I've worked with *.pl files. Am I correct in my thinking that the *.js executed server side, if written correctly can function like a *.pl in that it would read,write,append the db?

I understand the risks!

This post has been edited by EdNolan: 22 December 2013 - 12:27 PM

Was This Post Helpful? 0
  • +
  • -

#11 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 451
  • View blog
  • Posts: 1,946
  • Joined: 30-April 10

Re: Can javascript write to a file?

Posted 22 December 2013 - 01:51 PM

If you haven't read this yet then start here. It will help answer your questions about how node works.

Node works like any other server language.

  • client makes request to server for adding to DB
  • Node gets request on server and connects to DB
  • Node requests information be saved in DB
  • Items saved in DB
  • Success message sent back to client.

Was This Post Helpful? 1
  • +
  • -

#12 EdNolan  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 411
  • Joined: 22-September 13

Re: Can javascript write to a file?

Posted 22 December 2013 - 03:35 PM

I guess i need to ask. I am not using my own server soI am paying for the game to be hosted. Do I need to check if Node.js is installed on the hosting account? I read that I might need a dedicated if I go Node.js.
Was This Post Helpful? 0
  • +
  • -

#13 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10816
  • View blog
  • Posts: 40,315
  • Joined: 27-December 08

Re: Can javascript write to a file?

Posted 22 December 2013 - 03:40 PM

Yes, you would need to check. Your options are really:
-Use whatever is installed on the current server by the host. This may mean using a technology other than Javascript.
-Change hosts.
-Don't implement the feature. (A last resort option, but an option nonetheless).
Was This Post Helpful? 1
  • +
  • -

#14 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3834
  • View blog
  • Posts: 13,583
  • Joined: 12-December 12

Re: Can javascript write to a file?

Posted 22 December 2013 - 03:54 PM

This link may be useful:

Hosting compatible with Node

It is possible to install node.js on a hosted server but most free, or inexpensive, hosts probably won't permit this. It is far easier to choose a host that provides the technology you need.

This post has been edited by andrewsw: 22 December 2013 - 03:58 PM

Was This Post Helpful? 2
  • +
  • -

#15 EdNolan  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 411
  • Joined: 22-September 13

Re: Can javascript write to a file?

Posted 22 December 2013 - 07:49 PM

Looks like I am php bound. Here's what I need to do. As someone plays and increases their game money I wanted to let them spend that game money. Starting with $1000, once they reach $2000 they would be able to add a url and banner into the game database. The amount spent would determine how many impressions the URL and banner would be given. I was hoping javascript server side was possible. Your thought now please?
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3