我使用GET和POST请求在我的应用程序中多次应用RESTful约定。但这会导致我的JSON-server连接中断。有人知道这背后的原因是什么吗?你知道我为什么要面对这个问题吗?
我得到的错误是:
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我的日志文件是:
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 ]发布于 2020-09-07 22:38:24
在我的开发环境中,当对db.json文件进行了更改并且json-server自动重新加载时,我得到了相同的错误。有时,无论我指定哪个端口,它都会返回“端口已在使用”错误(100%确定该端口未被任何其他应用程序使用)。
通过在启动json-server时指定--host 127.0.0.1参数,我能够消除这个错误。
发布于 2021-08-25 10:28:30
使用3000端口时,我也遇到了同样的错误。我使用下面的命令在另一个端口上启动了我的服务器,我的问题得到了解决。json-服务器--观看db.json --端口3002
发布于 2019-12-04 14:10:28
该错误表示端口已被使用,请参阅json-server源代码:
process.on('uncaughtException', error => {
if (error.errno === 'EADDRINUSE')
console.log(
chalk.red(
`Cannot bind to the port ${error.port}. Please specify another port number either through --port argument or through the json-server.json configuration file`
)
)
else console.log('Some error occurred', error)
process.exit(1)
})尝试终止与该端口关联的节点进程并重新启动,或者通过--port参数指定一个新端口。
https://stackoverflow.com/questions/59169679
复制相似问题