Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

serve content from file vs database in node

I am making a new version of a old static website that grew up to a 50+ static pages.

So I made a JSON file with the old content so the new website can be more CMS (with templates for common pages) and so backend gets more DRY.

I wonder if I can serve that content to my views from the JSON or if I should have it in a MySQL database?

I am using Node.js, and in Node I can store that JSON file in memory so no file reading is done when user asks for data.

Is there a correct practise for this? are there performance differences between them serving a cached JSON file or via MySQL?

The file in question is about 400Kb. If the filesize is relevant to the choice of one tecnhology over the other?

like image 907
Rikard Avatar asked Dec 25 '15 08:12

Rikard


People also ask

Which is faster reading from file or database?

Especially in the case when small files are read first time, MySQL database is much faster than a pure filesystem. This is probably caused by better caching in MySQL database.

How do I read the contents of a file in node?

To get the contents of a file as a string, we can use the readFileSync() or readFile() functions from the native filesystem ( fs ) module in Node. js. /* Get all the contents from a file */ const content = readFileSync("myFile. txt");

Which is the correct way to read the contents of a file asynchronously and display the contents in console in node using fs module?

Use fs. readFile() method to read the physical file asynchronously.

Does Node.js have access to the file system of the server?

NodeJS is one of the most popular server-side programming frameworks running on the JavaScript V8 engine, which uses a single-threaded non-blocking I/O model. We can access the file system in NodeJS using some inbuilt modules.


1 Answers

Why add another layer of indirection? Just serve the views straight from JSON.

like image 158
hd1 Avatar answered Oct 22 '22 13:10

hd1