매우 간단한 DB와 API서버를 생성해주는패키지.
백엔드에서 실제 유와 API Server가 구축될 때까지 프론트엔드 개발에 임시적으로 사용할 mock data를 생성하기 위함.
json-server를 통해 백엔드가 하고 있는 작업을 기다리지 않고 프론트엔드의 로직과 화면을 구현할 수 있어 효율적인 협업이 가능하다.
CRA로 프로잭트 생성 → yarn이나 npm사용해서 설치
npm install -g json-server
yarn add json-server
db.json
생성 후 내용에 추가
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
JSON Server 시작
yarn json-server --watch db.json
yarn json-server --watch db.json --port 4000