I just installed json-server and ran it, then I got an error.
db.json
{
"user": {
"id": 0,
"name": "John"
}
}
a part of package.json
"scripts": {
"json-server": "json-server --watch db.json -port 5000"
},
I ran npm run json-server
and I got
> myproject@0.1.0 json-server
> json-server --watch db.json -port 5000
\{^_^}/ hi!
Loading db.json
Loading true
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received type boolean (true)
at Object.openSync (node:fs:591:10)
at Object.readFileSync (node:fs:467:35)
at /Users/admin/project/myproject/node_modules/json-server/lib/cli/run.js:118:32 {
code: 'ERR_INVALID_ARG_TYPE'
}
There is an issue but these solutions didn't work for me. Some people say use the latest react-scripts, so I use the latest one.
Thank you to read, can anyone solve it?
Change your command to
"scripts": {
"json-server": "json-server --watch db.json --port 5000"
},
You miss a "-" before -port. It should be --port.