javascript - 无法启动 "curl:localhost:3000"端口,显示 URI 错误

标签 javascript node.js curl backend

我刚刚开始开始使用 Node js,特别是启动服务器,并尝试使用新应用程序来 trim URL。但我被困在这里了。

环境:Windows

文本编辑器:VSCode

我的index.js代码:

/*
* Primary file for the API
*
*/
// Dependencies

var http = require('http');
var url = require('url');

// The Server shoudl respond to all requests with a string
var server = http.createServer(function (req, res) {
    // Get URL and Parse it
    var parsedUrl = url.parse(req.url, true);

    //Get the Path
    var path = parsedUrl.pathname;
    var trimmedPath = path.replace(/^\/+|\/+$/g, '');

    //Send the Response
    res.end('Hello World!\n');

    //Log the requst path
    console.log('Request recieved on path: ' + trimmedPath);

});

// Start the server, and have it listen on port 3000
server.listen(3000, function () {
    console.log("The server is listening on port 3000 now");
});

此后,我使用命令启动服务器

node index.js

它启动了服务器,然后我打开另一个终端并输入

curl localhost:3000

它给了我以下错误

curl : The URI prefix is not recognized.
At line:1 char:1
+ curl localhost:3000
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotImplemented: (:) [Invoke-WebRequest], NotSupportedException
    + FullyQualifiedErrorId : WebCmdletIEDomNotSupportedException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

最佳答案

http://https:// 一起使用。

例如:curl http://localhost:3000

关于javascript - 无法启动 "curl:localhost:3000"端口,显示 URI 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54561865/

相关文章:

php - PayPal REST API 送货地址不适用于 cURL 请求

php - 使用php和mysql记录curl GET请求的结果

javascript - 禁用除输入之外的文本选择

javascript - 如何在不使用 onclick 的情况下处理 ng-repeat 中的事件

javascript - Gulp less 然后缩小任务

javascript - React - 还有另一种方法来处理更新的状态,而不是将所有函数硬编码在 setState 方法的回调部分中?

javascript - 在express nodejs中将图像文件转换为base64

javascript - 以最短显示时间加载屏幕

javascript - Promise.all 和 Promise.race 有效地做出所有 promise "handled"是记录在案的行为吗?

php - Facebook API - 删除状态