I'm having some trouble using json-server
in the following way:
$ json-server --watch db.json
Every time I try to run that command, I encounter errors or warnings depending on the version of json-server
that is installed:
1.0.0-alpha.1
-1.0.0-alpha.12
:sh: json-server: command not found
or (if on Windows):
The term 'json-server' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + json-server --watch db.json
or (when executed via
npx
):npm ERR! could not determine executable to run
1.0.0-alpha.13
:node:internal/errors:496 ErrorCaptureStackTrace(err); ^ TypeError [ERR_PARSE_ARGS_UNKNOWN_OPTION]: Unknown option '--watch'. To specify a positional argument starting with a '-', place it at the end of the command after '--', as in '-- "--watch"
1.0.0-alpha.14
+:--watch/-w can be omitted, JSON Server 1+ watches for file changes by default
1.0.0-alpha.13
+, for users of Node.js versions prior to v18.3.0 and v16.17.0:import { parseArgs } from 'node:util'; ^^^^^^^^^ SyntaxError: The requested module 'node:util' does not provide an export named 'parseArgs'
Here's a simple package file (remember to update the version of json-server
accordingly):
{
"name": "q77787616",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "json-server --watch db.json"
},
"keywords": [],
"license": "ISC",
"dependencies": {
"json-server": "1.0.0-alpha.12"
}
}