Skip to content
Advertisement

Can’t start a “curl:localhost:3000” port, shows URI Error

I am just starting to begin node js, specifically starting up a server, and trying out a new app to trim out an URL. But I am stuck here.

Environment: Windows

Text Editor: VSCode

my code for 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");
});

After this, I start up the server using the command

node index.js

It shoots up the server and then I open another terminal and I type

curl localhost:3000

and it gives me the following error

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

Advertisement

Answer

Instead of using curl alone, add http to the URL to look something of this type:-

curl http://localhost:3000 (You can use your port number)

NB: https isn’t preferred

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement