Updated version of JSON Server (https://github.com/rbhachu/JSON-Server-Heroku) with House Keeping feature added to ensure db.json file is reset daily using Heroku Scheduler Plugin.
JSON Server v0.16.3 * - Creates a JSON REST API Server
Nodemon v2.0.7 * - Automatically restarts node application when file changes detected
* Installed automatically
Once the app is installed (see `Installation` section below), you can reset the db.json file in './data/' root folder by executing the following command in the terminal;
node ./bin/cleanup.js
This will run the cleanup.js file located in the './bin/' folder in the root of the site.
The cleanup.js file simply runs a function to overwrite the db.json file in the data folder with the original source values set in the db-source.json file.
The script (cleanup.js) can then be called potentially in your hosting platform via a scheduled task using the same command method as stated above.
NOTE: After testing the script in Heroku, although the script executes successfully, the db.json does not update to the original values set in the db-source.json file.
However, I do have another tested and working solution I have managed to establish, which will restart the App (resetting the JSON file to its initial state). More details here
Open your Code Editor and 'CD' into your working directory, then download the repo to that location, by executing the following command in your terminal.
git clone https://github.com/rbhachu/JSON-Server-Heroku-HK.git
Once the repo has been downloaded, 'CD' to the newly downloaded project folder. Then execute the following command in your terminal.
npm install
Also check for any updates by running the following command too.
npm update
Finally, to run the JSON server simply execute the following command in your terminal (ensuring you are in the correct project directory too).
npm start
After a few seconds, your browser should automatically open to the following link;
http://localhost:8000 and display the following Success
message in the browser page too.
You can also review the test db.json file data by clicking on the following links;
All Data: http://localhost:8000/blogs
Data for ID 1: http://localhost:8000/blogs/1
Data for ID 2: http://localhost:8000/blogs/2
If you encounter issues, please drop me a message via LinkedIn and I will try to help you resolve the issue.
👤 Rishi Singh Bhachu
Contact me via LinkedIn
If you liked this project it would be greatly appreciated to show your support by simply giving this repo a ⭐️ rating too, many thanks!