Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs JSON服务器连接中断_Reactjs_Rest_Npm_Axios_Json Server - Fatal编程技术网

Reactjs JSON服务器连接中断

Reactjs JSON服务器连接中断,reactjs,rest,npm,axios,json-server,Reactjs,Rest,Npm,Axios,Json Server,我正在使用GET和POST请求在我的应用程序中多次应用RESTful约定。但这会导致断开我的JSON服务器连接。有人知道这背后的原因吗?知道我为什么要面对这个问题吗 我得到的错误是: 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

我正在使用
GET
POST
请求在我的应用程序中多次应用RESTful约定。但这会导致断开我的
JSON服务器
连接。有人知道这背后的原因吗?知道我为什么要面对这个问题吗

我得到的错误是:

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 ]
0信息如果它以ok结尾,它就工作了
1 verbose cli['C:\\Program Files(x86)\\nodejs\\node.exe',
1 verbose cli'C:\\Program Files(x86)\\nodejs\\node\u modules\\npm\\bin\\npm cli.js',
1详细cli“开始”]
2信息使用npm@6.9.0
3信息使用node@v10.16.3
4详细的运行脚本['prestart','start','poststart']
5信息生命周期api@1.0.0~prestart:api@1.0.0
6信息生命周期api@1.0.0~start:api@1.0.0
7详细的生命周期api@1.0.0~start:生命周期中的不安全烫发为true
8详细的生命周期api@1.0.0~start:PATH:C:\ProgramFiles(x86)\nodejs\node\u modules\npm\node\u modules\npm lifecycle\node gyp bin;C:\Users\knowledge.seeker\Desktop\ReactMapGL\api\node\u modules\.bin;C:\Users\knowledge.seeker\bin;C:\ProgramFiles\Git\mingw64\bin;C:\ProgramFiles\Git\usr\local\bin;C:\ProgramFiles\Git\usr\bin;C:\ProgramFiles\Git\usr\bin;C:\ProgramFiles\Git\mingw64\bin;C:\ProgramFiles\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:\ProgramFiles(x86)\nodejs;C:\ProgramFiles\Git\cmd;C:\ProgramFiles(x86)\Thread\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\knowoledge.seeker\AppData\Local\warn\bin;C:\ProgramFiles\Git\usr\bin\vendor\u perl;C:\ProgramFiles\Git\usr\bin\core\u perl
9详细的生命周期api@1.0.0~start:CWD:C:\Users\knowledge.seeker\Desktop\ReactMapGL\api
10愚蠢的生命周期api@1.0.0~start:Args:['/d/s/c','json server-p3003-wdb.json']
11愚蠢的生命周期api@1.0.0~start:Returned:code:1信号:null
12信息生命周期api@1.0.0~start:无法执行启动脚本
13详细堆栈错误:api@1.0.0start:`json服务器-p3003-wdb.json`
13详细堆栈退出状态1
13 EventEmitter上的详细堆栈。(C:\ProgramFiles(x86)\nodejs\node\u modules\npm\node\u modules\npm lifecycle\index.js:301:16)
13 EventEmitter.emit上的详细堆栈(events.js:198:13)
13子进程上的详细堆栈。(C:\ProgramFiles(x86)\nodejs\node\u modules\npm\node\u modules\npm lifecycle\lib\spawn.js:55:14)
13 ChildProcess.emit上的详细堆栈(events.js:198:13)
13 maybeClose的详细堆栈(internal/child_process.js:982:16)
13 Process.ChildProcess.\u handle.onexit处的详细堆栈(internal/child\u Process.js:259:5)
14详细的pkgidapi@1.0.0
15详细cwd C:\Users\knowledge.seeker\Desktop\ReactMapGL\api
16详细窗口\u NT 10.0.17763
17详细argv“C:\\Program Files(x86)\\nodejs\\node.exe”C:\\Program Files(x86)\\nodejs\\node\u modules\\npm\\bin\\npm cli.js“开始”
18详细节点v10.16.3
19详细的npm v6.9.0
20错误代码ELIFECYCLE
21错误1
22错误api@1.0.0start:`json服务器-p3003-wdb.json`
22错误退出状态1
23发生错误时失败api@1.0.0开始脚本。
23错误这可能不是npm的问题。上面可能还有其他日志输出。
24详细退出[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服务器时,我在开发环境中遇到了相同的错误。有时它会返回“端口已在使用”错误,而不管我将指定哪个端口(100%确定它未被任何其他应用程序使用)


启动json服务器时,我可以通过指定
--host 127.0.0.1
参数来消除此错误。

是否有其他实例正在运行?当您指定另一个端口(如错误消息提示)时会发生什么情况?@adamz4008是。端口
(300013003)
同时运行。我得到这个错误只是因为
端口3003
@Knowledge Seeker您尝试使用端口3003有什么具体原因吗?你能试着把端口从3003换成别的吗。我之前也遇到过类似的问题,端口3003被阻塞,无法使用。所以,我不得不改变港口,一切都很顺利。我不知道为什么它被封锁了。我会尽量找到一些相关的链接,并张贴在这里。但现在试着使用3000、3001、3002或除3003以外的任何其他端口,告诉我它是否有效。@Sunil我担心。对于端口3002,我遇到了相同的错误。您有什么解决方案吗?我现在对
交叉点
使用了不同的端口号,但得到了相同的错误。