본문 바로가기

What I Learnd/TIL

TIL - Json Server 설치 & 사용법

 

json-server

셋팅하기 공식문서https://www.npmjs.com/package/json-server

 

json-server

Get a full fake REST API with zero coding in less than 30 seconds. Latest version: 0.17.3, last published: 3 months ago. Start using json-server in your project by running `npm i json-server`. There are 315 other projects in the npm registry using json-ser

www.npmjs.com

 

1. 설치

npm install json-server
// or
yarn add json-server

 

2. 실행 (기존 포트 영향주지 않기 위해 다른 포트 명령 사용)

json-server --watch db.json --port 4000

 

3. 로컬호스트 확인!

// db.json

{
  "posts": [
    {
      "id": 1,
      "title": "json-server",
      "author": "typicode"
    }
  ],
  "comments": [
    {
      "id": 1,
      "body": "some comment",
      "postId": 1
    }
  ],
  "profile": {
    "name": "typicode"
  }
}