With Node.js we can use a variety of database engines such as MySQL, Postgres, MongoDB, and so on. At a very high level, most databases offer the following four types of operations:
insert
, for adding new data to the database (e.g. a Twitter user sending a new tweet)remove
, for deleting existing data from the database (e.g. a Twitter user removing their tweet)update
, for updating existing data in the database (e.g. a Twitter user editing a tweet they’d already published), andfind
, for looking up data in the database (e.g. for seeing all tweets sent by a user, on their profile page.)For ease-of-use purposes, we will be using a simple database called nedb. nedb is a MongoDB compatible in-memory or on disk datastore that is quick and easy for us to work with without going through a big setup process.
In order to use it, we have to install it as we would any normal server side node module:
npm install --save nedb
Below is a quick reference to show you how to create a new database, as well as how the four types of operations mentioned above work. See the nedb documentation for more.