Mock Data for Angular 9 applications with JSON Server — Part 1

ng new angular-mock-data

Creating Angular application
Creating Angular application

cd angular-mock-data

npm install json-server — save-dev

Install json-server
Install json-server

{

“people”: response_from_api

}

data.json sample

“mock:server”: “json-server — watch mocks/data.json”

Add mock:server task to package.json

npm run mock:server

Running json-server
People api from json-server

“start:proxy”: “ng serve — proxy-config proxy.conf.json”

Add following code to the proxy.conf.json file:

Configuring proxy for /people route

npm run start:proxy

Running angular app with proxy

npm install concurrently --save-dev

Install concurrently

“start:proxy:mock:server”: “concurrently — kill-others \”npm run mock:server\” \”npm run start:proxy\””

Modified package.json

npm run start:proxy:mock:server

Using Concurrently to run both servers

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store