I am working on an express.js example app for personal reference. I want to save data, but I do not want to have to set up a database or anything right now.
I was wondering how I would save data to a file in express? It doesn't have to save per se, but I am trying to mimic a database using CRUD and RESTful routing.
Say I have this 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 say getBlogEntries
is index
, and getBlogEntry
would be show
, how would I go about mimicking create
, update
, and destroy
? Would the data be persisted or would it save in memory and disappear on page refresh?