Skip to content

Updated version of JSON Server (Back-End REST API Server for The Mojo Blog) with new `house keeping` feature.

Notifications You must be signed in to change notification settings

rbhachu/JSON-Server-Heroku-HK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Heroku

JSON Server + House Keeping
(Back-End API REST Server for The Mojo Blog)


Description

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.


Dependencies/NPM Modules

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

Usage

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.

Run Command

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.

Files

db-source.json file
File source

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



Installation

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

Deployment

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.

Site Preview

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

Site Preview

Issues

If you encounter issues, please drop me a message via LinkedIn and I will try to help you resolve the issue.

Author

👤 Rishi Singh Bhachu
Contact me via LinkedIn

Show your support

If you liked this project it would be greatly appreciated to show your support by simply giving this repo a ⭐️ rating too, many thanks!

About

Updated version of JSON Server (Back-End REST API Server for The Mojo Blog) with new `house keeping` feature.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •