无法启动“curl:localhost:3000”端口,显示 URI 错误

Viv*_*aik 4 javascript curl backend node.js

我刚刚开始使用 node js,特别是启动一个服务器,并尝试一个新的应用程序来修剪一个 URL。但我被困在这里。

环境:窗户

文本编辑器: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");
});
Run Code Online (Sandbox Code Playgroud)

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

node index.js
Run Code Online (Sandbox Code Playgroud)

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

curl localhost:3000
Run Code Online (Sandbox Code Playgroud)

它给了我以下错误

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
Run Code Online (Sandbox Code Playgroud)

小智 6

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

例如: curl http://localhost:3000


Kim*_* K. 5

不要单独使用curl,而是添加http到 URL 中以查看以下类型的内容:-

curl http://localhost:3000 (您可以使用您的端口号)

注意:https不是首选