Setting up a mock API with JSON Server

Michael Carneal
1 min readAug 5, 2019

Sometimes when you need to access a fairly large JSON file it may seem convenient to set up a API from scratch using any number of frameworks.

But other times if you just need a quick and dry way to access a REST API but without all the hassle of configuring one yourself.

Enter JSON SERVER

JSON server is a node package that can be easily added to any project. Lets say we have a JSON file saved in the root of our directory called index.json. The index.json file will act as an almost database that our front end can make requests and add to.

First we need to install the server using node package manager.

npm install -g json-server

With that installed we can now tell the JSON server to watch any particular .json file. In this case we will watch our index file.

json-server --watch index.json

This mock server will act as a full REST api with GET, POST, PATCH, and DELETE methods available.

This method works great when working with data sets that you need to quickly inspect or for small scale projects.

To learn more about the JSON server package please visit https://www.npmjs.com/package/json-server

--

--