运行一个node.js程序,该程序对在我的本地计算机上运行的Express服务器进行访存调用

y

如何在node.js中运行一个javascript程序,以对本地计算机上运行的服务器进行本地提取调用?

我有一个express正在侦听端口4001的本地服务器:

const express = require('express');
const app = express();  

const PORT = process.env.PORT || 4001;

app.listen(PORT, () => {
    console.log(`Server is listening on port ${PORT}`);
})

app.use('/test', (req, res, next) => {
    res.send('test');
})

我有一个单独的app.js文件可以node-fetch调用此服务器:

const fetch = require('node-fetch');

const payload = fetch('https://localhost:4001/test');

payload.then(response => response.json())
.then(jsonResponse => {
    console.log(jsonResponse);
}).catch(error => {
    console.log(error);
})

node app.js在终端中运行会导致以下错误消息:

FetchError: request to https://localhost:4001/test failed, reason: write EPROTO
15088:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\dep
s\openssl\openssl\ssl\record\ssl3_record.c:332:

    at ClientRequest.<anonymous> (C:\Users\lowys\projects\dump\node-test\node_mo
dules\node-fetch\lib\index.js:1455:11)
    at ClientRequest.emit (events.js:210:5)
    at TLSSocket.socketErrorListener (_http_client.js:406:9)
    at TLSSocket.emit (events.js:210:5)
    at errorOrDestroy (internal/streams/destroy.js:108:12)
    at onwriteError (_stream_writable.js:452:5)
    at onwrite (_stream_writable.js:473:5)
    at internal/streams/destroy.js:50:7
    at TLSSocket.Socket._destroy (net.js:664:5)
    at TLSSocket.destroy (internal/streams/destroy.js:38:8) {
  message: 'request to https://localhost:4001/test failed, reason: write EPROTO
15088:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\\ws\\d
eps\\openssl\\openssl\\ssl\\record\\ssl3_record.c:332:\n',
  type: 'system',
  errno: 'EPROTO',
  code: 'EPROTO'
}
亚历山大·斯塔索塞尔斯基

根据协议(EPROTO)错误,尝试定位,http而不要https给出它的localhost

const fetch = require('node-fetch');

const payload = fetch('http://localhost:4001/test');

payload.then(response => response.json())
.then(jsonResponse => {
    console.log(jsonResponse);
}).catch(error => {
    console.log(error);
})

除非您创建了某种根SSL证书并将该证书添加到您的计算机。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

是否有可能写一个shell脚本,需要输入然后将ssh到我的本地计算机上的服务器和运行脚本?

如何在Docker容器内的本地计算机上运行的MySQL服务器用于DropWizard应用程序?

Postgresql服务器正在本地计算机上运行,但psql无法连接

我应该对在单台计算机上运行的不同服务器进行docker化吗?

在单核计算机上群集node.js应用程序服务器时的任何好处

无法使用本地计算机作为服务器在客户端运行桌面应用程序

引导加载程序无法在我的计算机上运行

如何在不同计算机上运行的虚拟机上运行客户端服务器应用程序?

我怎样才能暴露我的本地计算机上我的搬运工容器运行我的Tomcat服务器之外?

只能从运行服务器的计算机访问Express Node.js服务器

在我自己的计算机中将龙卷风Web应用程序作为服务器运行

无法在本地计算机上运行一个简单的angular-bootstrap示例

Express JS-使用服务器端JS检查应用程序是否在本地主机上运行

一个人如何从另一台计算机运行安装在一台计算机上的程序?

在不同时区在一台计算机上运行服务器

从我的计算机在主机服务器中运行脚本并关闭计算机

无法运行我的第一个node.js程序?

在本地计算机上运行应用程序,并在远程显示器上显示GUI

从另一个脚本运行Node Package + Arguments

我是否需要在服务器计算机上同时运行Nginx和Jetty?

可以在远程服务器上运行的PHP处理我计算机上的文件吗?

如何在本地计算机上运行Play应用程序并让其他人从Internet访问该应用程序

在本地计算机上运行或调试MVC应用程序时为空白页

在计算机上运行apache2 httpd Web服务器时出错

在服务器上发布后运行但在本地计算机上正常运行时,在mvc 5中加载视图时出现异常

运行Date()。toLocaleString()可以在本地计算机上获得本地时间,但是在服务器上可以使用UTC

在本地计算机上运行点火

在多台计算机上运行调度程序

使应用程序在超高清计算机上运行