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