I am currently developing an express.js sample application for my own reference. I need to store data without setting up a database at the moment.
I am curious about how I can save data to a file in express. It doesn't necessarily have to persist, but I aim to simulate a database with CRUD and RESTful routing.
Imagine I have this content in data.js
var entries = [
{"id":1, "title":"Hello World!", "body":"This is the body of my blog entry. Sooo exciting.", "published":"01/01/2017"}];
exports.getBlogEntries = function() {
return entries;
}
exports.getBlogEntry = function(id) {
for(var i=0; i < entries.length; i++) {
if(entries[i].id == id) return entries[i];
}
}
If we consider getBlogEntries
as index
, and getBlogEntry
as show
, how should I approach emulating create
, update
, and destroy
? Will the data persist or will it be stored temporarily in memory and vanish upon refreshing the page?