Build a local json server

1. Install json-server globally (no matter which directory it is at this time) Insert picture description here
2. cd to the location of the current project folder and create a new folder jsonserver

Insert picture description here
3. Run npm init in the current directory

Insert picture description here
4. Install and run npm install json-server --save again

Insert picture description here

5. The directory structure at this time

--jsonserver

    --node_moduies

    --package-lock.json

    --package.json

6. Open the package.json file and change the content here to: json-server --watch Customize a json file

Insert picture description here
7. Create a new db.json under the folder

Insert picture description here
8. Write the content in db.json

Insert picture description here

9. After saving, enter npm run json:server on the command line

Insert picture description here

10. At this time, enter localhost:3000 in the browser to get the data of json:server

You can also execute json-server data.json directly in the terminal

Guess you like

Origin blog.csdn.net/qq_43248623/article/details/108256415