Quickly build local data interfaces with Json-server

Source: Internet
Author: User

1. Installation

Global installation Json-server:

npm  install  -g  json-server

If it is a Linux system or Mac system, you need to add sudo in front of the global installation, and then enter the ciphertext password.

sudo  npm  install  -g json-server

2. Testing

json-server -h                  //测试命令

If the following appears, the installation is successful!

3. Create a new folder, such as a new folder on the desktop Jsonserver. Then CD jsonserver. Go to the folder.

4. Installing the Dependent modules

install json-server --save

5. Modify the configuration file

Open a Package.json file and modify scripts as follows:

"scripts": {    "json:server": "json-server --watch db.json"},

6. Create a new JSON file

The above is Db.json, so also create a new Db.json file, and then write the JSON data.

{"Users": [{"Name":"TT","Phone":"123456789","Email":"[Email protected]","Age":"20","id":1,"CompanyID":1}, {"Name":"Dede","Phone":"123456789","Email":"[Email protected]","Age":"30","id":2,"CompanyID":2}, {"Name":"WF","Phone":"123456789","Email":"[Email protected]","Age":"23","id":3,"CompanyID":3}, {"Name":"MJ","Phone":"123456789","Email":"[Email protected]","Age":"45", "id": 4,  "CompanyID": 3}",  "companies": [{ "id":  1,  "name":  "Apple",  "description":  "Apple lalala!"}, { "id": 2, " name ": " Microsoft ", " description ": " Microsoft lalala! "}, {" id ": 3,  "name":  "Google",  "description":  "Google lalala!"} ]} 

7. Running

npm run json:server

Run with the command, in fact, is running Json-server--watch Db.json. will provide a port 3000 address, view the page, after loading, you can see the relevant content. If there is an error, you can try:

npm run json:server



Quickly build local data interfaces with Json-server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.