Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express.js- Why is Localhost '::'

Can anyone tell me why my server address (host) is :: and not localhost

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

// respond with "hello world" when a GET request is made to the homepage
app.get('/', function(req, res) {
  res.send('hello world');
});

var server = app.listen(3000, function () {
  var host = server.address().address;
  var port = server.address().port;
  console.log('Example app listening at http://%s:%s', host, port);
});

This returns

Example app listening at http://:::3000

It works fine when I go to http://localhost:3000/

like image 913
Davetherave2010 Avatar asked Jul 25 '15 16:07

Davetherave2010


People also ask

What is locals in ExpressJS?

locals is an object that contains the local variables for the response which are scoped to the request only and therefore just available for the views rendered during that request or response cycle.

Why should you separate Express APP and server?

Applying a similar concept to the project structuring of Express, the separation of the application logic from the server allows the code to be modular and follow a MVC (Model-View-Controller) model. The separation is essential to reduce coupling and to encapsulate and abstract the inside logic of application.

Why we use Express instead of NodeJS?

Node JS is a fast JavaScript runtime environment that we use to build server-side applications, but it does not know how to perform serving files, handling requests, and handling HTTP methods, so this is where express js comes in.

Is ExpressJS a server?

js: Express is a small framework that sits on top of Node. js's web server functionality to simplify its APIs and add helpful new features. It makes it easier to organize your application's functionality with middle ware and routing.


1 Answers

Because :: is localhost when using IPv6, just like it is 127.0.0.1 in IPv4.

like image 125
idstam Avatar answered Oct 09 '22 20:10

idstam