JSON-Server 사용하여 임시 서버 만들기

프동프동·2022년 9월 23일
0

Node.js

목록 보기
2/2

npm을 이용해 JSON Server 설치

npm i json-server

작업 폴더에 db.json 파일 생성

  • 사용하고자 하는 데이터를 해당 파일에 Json문법으로 입력해둔다.
{
  "posts": [
    { "id": 1, "title": "json-server", "author": "typicode" }
  ],
  "comments": [
    { "id": 1, "body": "some comment", "postId": 1 }
  ],
  "profile": { "name": "typicode" }
}

서버 시작

json-server --watch db.json

서버 시작 (포트 번호 변경)

json-server --watch db.json --port 3004

결과

Resources URL로 이동 시 간단히 사용하기 좋은 서버가 세팅된 것을 확인할 수 있다.

profile
좋은 개발자가 되고싶은

0개의 댓글