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 trialMichael Medvedskiy
4,588 PointsButton changes html-document on server
Greetings!
Me and my friends are doing this project, one of them is sick and I have to do his part.
I've really simplified it to "I have an input and a button on a page with 1 element - <ul>. I click the button, the content of the input gets added to the html's <ul> as <li>".
I've been through js course, and there we were doing a similar thing, BUT it was on client side, and, when the page was refreshed, the changes disappeared. Is there a way for me to somehow make js send a signal to the server through html (I learned Spring framework for java), and make it change the html document located on the server?
1 Answer
Utku Akgüner
12,072 PointsYou are going to have to use some NodeJS to store your data as JSON file using "fs" library. Start by installing NodeJS to your device. You are going to require a library called "fs" in order to save your file as JSON. Check out this link https://gyandeeps.com/json-file-write/. You can basically change the .txt to .json at the end of the documentation to save as JSON which then you can retrieve as JSON file by requiring it in your file( var jsonFile = require("./file.json") ). As final you have to parse the json using( var data = JSON.parse(jsonFile) ). Hope this help, it is a though problem to solve without using databases so goodluck. You can check this link for more JSON parsing information https://www.w3schools.com/js/js_json_parse.asp
Michael Medvedskiy
4,588 PointsMichael Medvedskiy
4,588 PointsSo, NodeJS will be able to satisfy my needs (in terms of changing the distant html, not the one I currently have loaded in my browser window)?
Utku Akgüner
12,072 PointsUtku Akgüner
12,072 PointsI mean what you are asking is to store <li> elements dynamically in a file. In my experience using JSON is the simplest way to store data. Im pretty sure that there is another way around without using NodeJS but thats the simplest way i know that can satisfy your needs.