Json-server is a Node module that runs the Express server. You can specify a JSON file as the data source for the API. In other words, we can use it to build a Web server quickly.
- Address: github.com/typicode/js…
Steps:
- Make sure node is installed on your computer and then install jSON-server:
node -v
npm install -g json-server
Copy the code
- Deploy the JSON file.
The db.json file is as follows:
{
"posts": [{"id": 1."title": "json-server"."author": "typicode"}]."comments": [{"id": 1."body": "some comment"."postId": 1}]."profile": { "name": "typicode"}}Copy the code
Open the terminal in the db.json file directory. If you’re in vscode, open the db.json file and go to terminal -> new terminal. Enter:
json-server --watch db.json
Copy the code
— Watch stands for monitoring, which immediately displays changes to the data in a db.json file. If you see the following interface, it is successful. 3000 here is the port number assigned to it.
If the following error is reported, it is because of a script security problem. You need to change PowerShell’s security policy.
The steps to change PowerShell security policies are as follows:
- Start Power Shell as an administrator
- The input
Get-ExecutionPolicy
To view the current policy - The input
Set-ExecutionPolicy RemoteSigned
, set the current policy as the remotesunet
Next, you can access the data in Resources and Home.