The FileDataStore
class
This data store persists its data to JSON files, which means the data doesn’t go away when your app restarts, like it does with the MemoryDataStore. This allows you to easily create an API that acts like it has a real database behind it, so you can use the Mock middleware to create some data, and then use that data for a demos and presentations days or weeks later.
NOTE: The
FileDataStore
is not intended to replace a full-featured database. It does not provide features such as fault-tolerance, transactions, concurrency, etc. However, you can easily integrate with a full-featured database system (such as MySQL, SqlLite, Oracle, etc.) by creating your own class that inherits from the DataStore base class. You simply need to override the__openDataStore
and__saveDataStore
methods. See the FileDataStore source code for an example.
Constructor
FileDataStore(baseDir)
- baseDir (optional) -
string
The directory where the JSON files will be saved. TheFileDataStore
will create separate folders and files under this directory for each path in your Swagger API.
If you don’t specify this parameter, then it defaults toprocess.cwd()
.
Methods
The FileDataStore
class inherits from the DataStore class, so it has all the same methods for retrieving, saving, and deleting data.