Unable to assign an IP address to an Express JS application

Struggling to test a specific endpoint in Express, but consistently encountering a 404 error.

var express = require("express")
var app = express()
//var http = require('http').Server(app)
app.get('/', function(req,res){

        res.send('Endpoint working fine')
})
var port = process.env.PORT|| 8080
var localhost = 'someLocalHost.med.gov'
console.log({'localhost':localhost,
                'post':port})
//
app.listen(port,localhost,function(err){

        if (err){
                console.log('Error occurred')
        }
        else {
                console.log('Listening on specified port')
        }
})
When attempting to access , I consistently receive a 404 error response.

Answer №1

When we talk about "Localhost", what we really mean is the IP address 127.0.0.1. It's not as simple as launching a server on any random address you choose. If you're looking to make changes to how localhost works, one option is to edit your HOSTS file on your local machine to create an alias for localhost.

Answer №2

After trying several options, I finally accessed the site by typing in the IP address followed by port 8080.

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

Common reasons why you may encounter the error "Uncaught TypeError: $(...).DataTable is not a function"

I recently started working with DataTable.js, and when I tried to integrate it into my ASP.NET Core MVC 5.0 project, I encountered an error: Uncaught TypeError: $(...).DataTable is not a function After doing some research on Google, I discovered that this ...

Expressing the Asynchronous Callback

Is there a way for Node to calculate a complex task and immediately return a status of 202 Accepted, with the calculation progress being checked using a Poller? Any suggestions? I've implemented a similar setup in my Node/Express Endpoints: module.e ...

The error message received is: "mongoose TypeError: Schema is not defined as

Encountering a curious issue here. I have multiple mongoose models, and oddly enough, only one of them is throwing this error: TypeError: Schema is not a constructor This situation strikes me as quite odd because all my other schemas are functioning prop ...

Dividing an array into categories with typescript/javascript

Here is the initial structure I have: products = [ { 'id': 1 'name: 'test' }, { 'id': 2 'name: 'test' }, { 'id' ...

Error message "e.nodename undefined when set to setTimeout" was encountered

I developed a unique piece of code for input boxes located at the top of different tables. By using a class='filt', the table can be filtered based on the inputs provided. However, most of the inputs consist of more than one letter, so I wanted t ...

The Docker-compose configuration does not have the expected port exposed for the PostgreSQL database

I am currently working on setting up a multiservices architecture in my Node.js backend using Docker. I have two services running with separate databases. version: "3" services: server-api-getaway: build: context: "." ...

Creating raw JavaScript from npm package:How to convert npm modules into plain

Is there a way to get a pre-compiled plain JavaScript file from the repository https://github.com/airbrake/airbrake-js? I'm looking for a solution without using bower, npm or any other tools - just a single JavaScript file. By the way: The file "http ...

Dynamic text input and selection menu with AJAX (PHP and JavaScript)

As a student who is new to Javascript and PHP, I am trying to create a login page for my website that can verify user input in the database using AJAX. For example, when a user enters their username and password, the system should automatically check if t ...

Django does not support running JavaScript natively

Wondering how to incorporate JavaScript into Django for creating chained forms? My first step was simply trying to understand how to run JavaScript. I've placed a basic main.js file in the static folder. I included a link to main.js in the header of ...

Interrupt the sequence of promises - prevent the subsequent 'then' function from running

I'm currently working on developing a registration system using Node/Express and I've been experimenting with Promises. However, I've encountered an error message while incorporating them: Error: (node:64725) UnhandledPromiseRejectionWa ...

What strategies and techniques should be considered when creating websites optimized for mobile devices?

With a wealth of experience in programming languages like Java, Python, and C, I actively engage in self-study to enhance my skills. While I have dabbled in creating mobile-friendly websites, upon reviewing my work, it is evident that my frontend developme ...

SignalR 2.2 users are experiencing a lack of message reception

I have developed a unique self-hosted SignalR application that is operating within the framework of a console application. To access the hubs within this application, I have implemented a wrapper class to avoid referencing the SignalR.Core assemblies direc ...

Is JQuery the ultimate solution for creating a dynamic multi-language website?

Embarking on a new project that requires support for multiple languages. My plan is to create a jQuery/AJAX based application with all the code in jQuery, simply calling JSONs for data. What would be the most effective approach for implementing multi-lan ...

Unable to decrease the width of a div element in Vuetify and Nuxt

As I work on creating a dynamic form with fields that need to occupy only 50% of the size of a regular field, I encounter different components based on data provided by Vuex. The use of v-for in Vue.js helps me loop through form objects and render the app ...

Ways to prevent adding duplicate elements to a state array in React.js?

The state provided below is within my class component. I need to prevent adding duplicate objects to an array in my state as shown below: this.state = { frequency: { time: [ {time:"20:15",timezone:"IST"}, ...

Troubleshooting an expressjs server in parallel with electron

I have managed to successfully run an ExpressJS server alongside Electron by following the instructions provided in this post: Run Node.js server file automatically after launching Electron App However, I am facing an issue where there is no output from t ...

Generate a new object from the contents of a div

Having the HTML structure below: <div id="main"> <div id="myDiv1"> <ul> <li>Abc</li> <li>Def</li> </ul> </div> <div id="myDiv2"> <ul> <li>Ghi</l ...

Tracking the advancement of synchronous XMLHttpRequest requests

Within the client-side environment, there exists a File-Dropzone utilizing the HTML5 File-API which allows users to drop multiple files for uploading to the server. Each file triggers the creation of a new XMLHttpRequest Object that asynchronously transfer ...

Warning: When VueJs OnMount props is utilized, it might display a message stating, "Expected Object, received Undefined."

This is my current component setup: <template> <Grid :items="items" /> </template> <script setup> import { ref, onMounted } from 'vue' import Grid from '@/components/Grid.vue' import { getData ...

Encountering connection closure while using the http GET method in a Node.js application with Express framework

My issue involves receiving a connection close header in response when making a GET request, but the connection remains keep-alive for POST requests. My current setup includes an AWS ALB directing traffic to EKS. Within EKS, there is an NGINX ingress rout ...