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

时间:2019-02-06 20:16:47

标签: javascript node.js curl backend

我刚刚开始开始节点js,特别是启动服务器,并尝试使用新的应用程序来修剪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

2 个答案:

答案 0 :(得分:4)

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

例如:curl http://localhost:3000

答案 1 :(得分:0)

向URL添加import download from "downloadjs"; export const downloadFile = async (fileName) => { axios({ method: "get", url: `/api/v1/users/resume/${fileName}`, responseType: "blob", }).then(function (response) { download(response.data, fileName); }); }; 而不是单独使用curl来查找这种类型的东西:-

卷曲http:// localhost:3000(您可以使用端口号)

注意:http不是首选