Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Mostafa El
3,202 PointsOverwrite existing .js file
Hey guys, I've been trying to do this for a while now and been looking and tried many things but nothing seems to be working. I have a button on my index.html which I want to call a function to write a string to an existiong .js file.
I know I can't use a client-side lang for this but what do you recommend ,why and how? PHP, Perl, Node? Take into consideration I'm hosting on Godaddy. Cheers
3 Answers
James Barnett
39,199 PointsI would like to be able to modify that content and once the user clicks save the new objects
- Do you want this data available only to that particular client? if so you can use JSON and localStorage
- You can also check out firebase
Mostafa El
3,202 PointsThanks Dave and thanks James I will be checking firebase out. Thanks again
Mostafa El
3,202 PointsHey Dave, Currently I have a Web page where all the content is store in a js file as objects and the script on the page populates all the tags with the proper content. Now I would like to be able to modify that content and once the user clicks save the new objects are written to the file.
Dave McFarland
Treehouse TeacherI'm not sure JavaScript is the best solution for this problem. Sounds like you need a database and server side solution. Perhaps you should try our Php or Ruby on Rails tracks. You can use javascript and a server side solution without needing to write javascript files on the server.
Mostafa El
3,202 PointsThat's exactly what I thought and I've tried using fopen() and fwrite() but that was an epic fail.
Dave McFarland
Treehouse TeacherDave McFarland
Treehouse TeacherHi Could you explain what you're trying to accomplish and why? I'm not sure why you'd want to write to a js file.