Vue.js 3 npm json-server 패키지
21 Mar 2022 | Vue.jsjson-server 패키지
json-server는 json 파일을 이용해서 간단한 REST 서버를 만들어주는 npm 패키지입니다.
여기에서 설명을 볼 수 있습니다.
설치 방법
npm install -g json-server
Database 파일 작성
db.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
\{^_^}/ hi!
Loading db.json
Done
Resources
http://localhost:3000/posts
http://localhost:3000/comments
http://localhost:3000/profile
Home
http://localhost:3000
Type s + enter at any time to create a snapshot of the database
Watching...
json 파일에 따라 REST API가 자동으로 만들어지며, json 파일을 수동으로 변경하더라도 자동으로 서버에 적용됩니다.