Storing notes in files
An often underlooked database engine is the filesystem. While filesystems don't have the sort of query features supported by database engines, they are a reliable place to store files. The notes schema is simple enough that the filesystem can easily serve as its data storage layer.
Let's start by creating a directory for the model code:
$ mkdir models-fs $ touch models-fs/notes.js
Then in models-fs/notes.js
we start adding code:
var fs = require('fs'); var path = require('path'); var async = require('async'); var _dirname = undefined; exports.connect = function(dirname, callback) { _dirname = dirname; callback(); } exports.disconnect = function(callback) { callback(); }
The connect
and disconnect
functions will be used in each model to connect to or disconnect from the database. The first parameter to the connect
function is meant to be data required to connect with, say, a database engine, such as the connection URL. In this case it is simply the directory...