I'm using GET
and POST
requests to apply RESTful conventions multiple times in my application. But this results in breaking my JSON-server
connection. Does anyone know what is the reason behind this? Any idea that why I'm facing this problem?
Error that I'm getting is:
POST /points/ 201 10.344 ms - 289
POST /intersections/ 201 15.447 ms - 504
POST /points/ 201 7.159 ms - 307
POST /intersections/ 201 12.089 ms - 486
db.json has changed, reloading...
Loading db.json
db.json has changed, reloading...
Done
Resources
http://localhost:3003/streams
http://localhost:3003/intersections
http://localhost:3003/points
Home
http://localhost:3003
db.json has changed, reloading...
Loading db.json
db.json has changed, reloading...
Done
Resources
http://localhost:3003/streams
http://localhost:3003/intersections
http://localhost:3003/points
Home
http://localhost:3003
Cannot bind to the port 3003. Please specify another port number either through --port argument or through the json-server.json configuration file
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! api@1.0.0 start: `json-server -p 3003 -w db.json`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the api@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\knowledge.seeker\AppData\Roaming\npm-cache\_logs\2019-12-04T05_34_11_867Z-debug.log
My log file is:
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files (x86)\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'start' ]
2 info using npm@6.9.0
3 info using node@v10.16.3
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle api@1.0.0~prestart: api@1.0.0
6 info lifecycle api@1.0.0~start: api@1.0.0
7 verbose lifecycle api@1.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle api@1.0.0~start: PATH: C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\knowledge.seeker\Desktop\ReactMapGL\api\node_modules\.bin;C:\Users\knowledge.seeker\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\knowledge.seeker\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files (x86)\nodejs;C:\Program Files\Git\cmd;C:\Program Files (x86)\Yarn\bin;C:\Users\knowledge.seeker\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Users\knowledge.seeker\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\knwoledge.seeker\AppData\Local\Yarn\bin;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
9 verbose lifecycle api@1.0.0~start: CWD: C:\Users\knowledge.seeker\Desktop\ReactMapGL\api
10 silly lifecycle api@1.0.0~start: Args: [ '/d /s /c', 'json-server -p 3003 -w db.json' ]
11 silly lifecycle api@1.0.0~start: Returned: code: 1 signal: null
12 info lifecycle api@1.0.0~start: Failed to exec start script
13 verbose stack Error: api@1.0.0 start: `json-server -p 3003 -w db.json`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack at EventEmitter.emit (events.js:198:13)
13 verbose stack at ChildProcess.<anonymous> (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:198:13)
13 verbose stack at maybeClose (internal/child_process.js:982:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid api@1.0.0
15 verbose cwd C:\Users\knowledge.seeker\Desktop\ReactMapGL\api
16 verbose Windows_NT 10.0.17763
17 verbose argv "C:\\Program Files (x86)\\nodejs\\node.exe" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
18 verbose node v10.16.3
19 verbose npm v6.9.0
20 error code ELIFECYCLE
21 error errno 1
22 error api@1.0.0 start: `json-server -p 3003 -w db.json`
22 error Exit status 1
23 error Failed at the api@1.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
I was getting the same error in my development environment, when changes to the db.json file were made and the json-server automatically reloaded. Sometimes it would come back with the "port already in use" error, regardless of which port I would specify (100% certain it was not used by any other application).
I was able to get rid of this error by specifying the --host 127.0.0.1
parameter when starting the json-server.