Processing Data with Node
Processing Data with Node
This blog post will address and analyze a few of the ways to pass and manipulate data using Node.JS.
Storing the Data
There are three primary ways to store and manipulate data using Node:
- Global Variables
- External Files (such as JSON)
- Remotely Stored Databases
When deciding which of these data input methods, a Node programmer should consider two things: the size of their dataset and what sorts of manipulations they hope to perform on their data.
Global Variables
A global variable is a variable which exists as a part of the memory of an application on a single run. For instance:
Using global variables to store data, especially for web-servers, often lends itself to undesirable repercussions, such as:
- losing data to memory resets when the application is re-run
- stack overflow if the variable grows too large
Files
As opposed to storing data in a global variable within the application, data can also be written to a file and stored in a file system.
Writing to files is more cost efficient than writing to a database. Additionally, Node has a special file format with which it is extremely compatible: JSON files. JSON is a lightweight file format, where entries are represented as JavaScript objects and thus have values which can be easily accessed in JS.
In the example above, we have created a JSON object called jsonArr
. The variable x
stores the name
attribute of the object, which in this case is Vish.
While appending entries to JSON files is easy, inserting or deleting entries within JSON files is quite inefficient.
Databases
There are two primary sorts of databases: SQL and NoSQL. Their different uses are shown in the table below.
SQL | NoSQL |
---|---|
Data stored in tables; each entry is its own row in the table. | Users can store any JSON objects. |
User must define schemas, where the datatypes for the values to be stored must be declared explicitly prior to storing data. | No schema requirement. |
The structured schemas of SQL allow for fast database querying with complex searches. On the other hand, NoSQL permits users to store large amounts of structured or unstructured data. NoSQL is more flexible than SQL at the expense of consistency. Additionally, no one entry is visible in NoSQL databases, since entries are stored as objects.
Sources
- https://blog.risingstack.com/node-js-database-tutorial/
- https://www.codementor.io/codementorteam/how-to-use-json-files-in-node-js-85hndqt32
- https://stackoverflow.com/questions/383692/what-is-json-and-why-would-i-use-it
- https://blog.cloud-elements.com/json-better-xml
- https://www.tablesgenerator.com/markdown_tables
- https://www.w3schools.com/js/js_json_objects.asp
- https://medium.com/markdown-monster-blog/getting-images-into-markdown-documents-and-weblog-posts-with-markdown-monster-9ec6f353d8ec