I'm pretty sure doing everything correctly. I'm using these version:
"axios": "^0.24.0",
"json-server": "^0.17.0",
I've followed the official doc. I've db.json
in the root folder itself.
{
"users": [
{
"ID": 1,
"Username": "mike",
"Password": "User1Password"
},
{
"ID": 2,
"Username": "robert",
"Password": "User2Password"
}
]
}
I'm running json-server
with this command:
json-server --watch db.json --port 4000
Whenever I hit http://localhost:4000/users
I'm served with this:
\{^_^}/ hi!
Loading db.json
Done
Resources
http://localhost:4000/posts
http://localhost:4000/comments
http://localhost:4000/profile
Home
http://localhost:4000
Type s enter at any time to create a snapshot of the database
Watching...
GET /users 404 4.800 ms - 2
But rest of the end points like:
http://localhost:4000/posts
http://localhost:4000/comments
http://localhost:4000/profile
are working absolutely fine. Please help.
CodePudding user response:
Copying my own comment to an answer as requested:
You said db.json
is in the src
folder. What matters is that it's in the same folder where you started the server. It sounds like it created a default db.json
somewhere else and is using that.
CodePudding user response:
According to @user2740650
You said db.json is in src folder. What matters is that it's in the same folder where you started the server. It sounds like it created a default db.json somewhere else and is using that.
Second Scenario
move your db.json file into the Public folder and calling it by: axios.get('db.json') .then(//...)