Reputation: 35
I'm new to Node.js and have written an chat in Node.js trough socket.io. It works well.
But what disturbs me is, when i reload the page, the whole chat data is gone. The chat box is clear.
How i can save all the data? Is it possible without logging anything?
Upvotes: 1
Views: 1157
Reputation: 508
What your looking for is a database. Don't think that this just means a MySQL database, as it also includes XML files, text files, JSON files, and a lot more.
To start off, take @Brandon's advice and learn how to append each chat message into the file. When your page reloads, iterate over each line of text or data entry and add it to the chat program.
Here's some helpful links:
How to append to a file in Node?
How to update a value in a json file and save it through node.js
How to parse JSON using Node.js?
https://docs.mongodb.org/getting-started/node/
Upvotes: 2