JSON-服务器连接中断
JSON-server connection breaks
我正在使用 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\_logs19-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 ]
该错误表示端口已被使用,请参阅json-服务器来源:
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 参数指定一个新端口。
当对 db.json 文件进行更改并自动重新加载 json-server 时,我在我的开发环境中遇到了同样的错误。有时它会返回“端口已在使用”错误,无论我指定哪个端口(100% 确定它没有被任何其他应用程序使用)。
通过在启动 json-server 时指定 --host 127.0.0.1
参数,我能够摆脱这个错误。
我在 3000 端口上也遇到了同样的错误。我使用以下命令在另一个端口上启动了我的服务器,我的问题就解决了。
json-server --watch db.json --port 3002
我正在使用 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\_logs19-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 ]
该错误表示端口已被使用,请参阅json-服务器来源:
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 参数指定一个新端口。
当对 db.json 文件进行更改并自动重新加载 json-server 时,我在我的开发环境中遇到了同样的错误。有时它会返回“端口已在使用”错误,无论我指定哪个端口(100% 确定它没有被任何其他应用程序使用)。
通过在启动 json-server 时指定 --host 127.0.0.1
参数,我能够摆脱这个错误。
我在 3000 端口上也遇到了同样的错误。我使用以下命令在另一个端口上启动了我的服务器,我的问题就解决了。 json-server --watch db.json --port 3002