The output of server.address() method in Node.js is ::

My memory serves me right, a few days back it was showing "localhost". I'm puzzled as to what altered server.address().address to now return double colons (::). According to my research, it seems to be returning an IPv6 address (::) because it's enabled, although it's actually disabled on my computer. For more information, you can visit: https://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback

Answer №1

According to the documentation,

The server will start accepting connections on the specified port and hostname. If no hostname is provided, it will accept connections on any available IPv6 address (::) when IPv6 is available, or any IPv4 address (0.0.0.0) otherwise. Setting the port value to zero will result in a random port assignment.

Therefore, the code below would display running at http://:::3456:

var express      = require('express');
var app          = express();
var server = app.listen(3456, function () {
    var host = server.address().address;
    var port = server.address().port;
    console.log('running at http://' + host + ':' + port)
});

However, if you include a specific hostname:

var server = app.listen(3456, "127.0.0.1", function () {

The output would be as follows: running at http://127.0.0.1:3456

Additionally, using an IP library as suggested in this post may be beneficial.

Answer №2

It appears that the selection of an IPV6 address is likely due to another application utilizing port 3456 for IPV4 communication. This situation can occur following automatic software updates, which may introduce new processes.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How I am able to access this.state in React without the need for binding or arrow functions

Understanding the concept of arrow functions inheriting the parent context is crucial in React development. Consider this React component example: import React, { Component } from 'react'; import { View, Text } from 'react-native'; i ...

Webpack2 now transforms sass/scss files into JavaScript rather than CSS during compilation

I've created a webpack script to compile all .scss files into one css file. I decided to use webpack instead of gulp or grunt for simplicity, as it can be configured in a single file. However, I am encountering an issue where scss files are being com ...

Passing a JavaScript object that may be undefined to a pug template in Node.js

My journey requires transferring a set of JavaScript objects to the pug template. router.get('/edit/:itemObjectId', async function(req, res, next) { var itemObjectId = req.params.itemObjectId; var equipmentCategoryArr = []; var lifeE ...

Deactivate the remotebuild agent on a Mac to ensure security is not compromised

I am currently working on developing an app using Cordova on my Mac. To facilitate this process, I installed the remotebuild package via npm. After completing the installation, it was necessary to set "remotebuild --secure false" but when attempting to d ...

Error: jQuery Validation not triggering in Bootstrap modal window

My attempts to use jQuery Validation for form validation inside a modal have hit a dead end. The validation doesn't trigger at all, not even an error message is displayed. Upon debugging, a warning emerged: No elements selected for validation; retu ...

Iterating over a nested document containing subarrays and rendering them on an EJS template

My aim here is to iterate through an embedded document and display comments for the posts with matching IDs. This is my Schema structure on the node.js server: var postSchema = new mongoose.Schema({ name: String, post: String, comment: [ ...

javascript - substitute the dash (hyphen) with a blank space

For quite some time now, I've been on the lookout for a solution that can transform a dash (hyphen) into a space. Surprisingly, despite finding numerous responses for changing a space into a dash, there seems to be a scarcity of information going in t ...

Express router is unable to process POST requests, resulting in a 404 error

I am having trouble fetching POST requests to my Express router. While my many GET requests work fine, this is my first POST request and it is not functioning correctly. Here is a snippet of my frontend code: export async function postHamster(name, age) ...

Nodemailer functions flawlessly when used locally, but experiences issues when deployed live

function sendEmail(num, email, customerName) { var readHTMLFile = function (path, callback) { fs.readFile(path, { encoding: 'utf-8' }, function (err, html) { if (err) { throw err; callback(e ...

Melodic alerts from Node-webkit

I have developed a function in my node-webkit application to display OS X notifications. While it works flawlessly, I'm curious if there is a way to customize the sound instead of the default iPhone ding? I referred to the official notification API d ...

Can you please explain the meaning of _user in the test file that was

I encountered a reference error while working on a test project assigned by my employer. This issue arose when I reached the final test and came across the term "_user". Can anyone explain what does this mean in this context? 'use strict' l ...

Choosing the following choice using the Material-UI Select tool

Looking for a way to enhance my dropdown select from MUI in a Nextjs application by adding two arrows for navigating to the next/previous option. Here's what my code currently looks like: <StyledFormControl> <Select value={cu ...

What methods can I use to prevent a JavaScript array from getting filled during page loading?

Looking for assistance to populate an array using JQuery with option values from multiple select elements. I need the array to reset and fill with new options each time a select element is used. Strangely, despite my efforts, the array appears pre-filled w ...

Suggestions for updating the 'begin' and 'finish' variables transmitted through ajax on fullcalendar?

Shown below is the URL to request JSON data via Ajax: '/php/get-events.php?start=2015-05-31&end=2015-06-07&_=1433154089490'. This query will fetch JSON data from 2015-05-31 to 2015-06-07. However, I am looking to retrieve data over a ...

Finding and removing the last portion of the innerHTML can be achieved by employing specific techniques

Looking to manipulate a <div> element that includes both HTML elements and text? You're in luck. I need to locate and remove either the last, nth-from-last, or nth plain text section within it. For example: <div id="foo"> < ...

Is it possible to have nullable foreign keys using objectionjs/knex?

It seems like I'm facing a simple issue, but I can't quite figure out what mistake I'm making here. I have a table that displays all the different states: static get jsonSchema() { return { type: 'object', propert ...

Why is the updated index.html not loading with the root request?

I'm currently working on an Angular app and facing an issue with the index.html file not being updated when changes are made. I have noticed that even after modifying the index.html file, requests to localhost:8000 do not reflect the updates. This pro ...

What's the best way to capture an element screenshot using JavaScript?

I'm working on developing a unique gradient selection application. One of the exciting features I would like to incorporate is the ability for users to save their chosen gradients as digital images (.jpg format) directly onto their computers. When the ...

Using Javascript to update text content by utilizing `innerText` property instead of checking if it is

How can I selectively use Javascript to replace the specific word "Rindan" in the text below, but not if it appears within an attribute such as img alt=="Rindan"? I only want to replace instances of the word "Rindans" when it is part of the inner text an ...

Ensure that the extension is only loaded once Angular has fully loaded

I am currently working on a Chrome extension that incorporates event listeners to elements within a page utilizing Angular 1.2.10. The following code snippet is an example of what I have: window.addEventListener("load", (event) => { var switchButton = ...