Express is capable of running on dual ports simultaneously, irrespective of the specified port

When launching my express app, I typically use app.listen(PORTNO).

The app usually runs on 127.0.0.1:PORTNO, but oddly enough it also seems to run on 127.0.0.1:3000.

As far as I know, 3000 is the default port for express applications.

Does anyone understand why this unexpected behavior is happening?

I've attempted changing the environment variable to production and even tried using

http.createServer(app).listen(PORTNO);

My express app files are generated through express-generator.

In case it matters, I'm working on a Windows machine.

UPDATE: I start the server with npm start which executes bin\www, setting the port for running the server. However, this still doesn't clarify why the app seems to bind to two different ports - one specified in app.js and the other in bin\www - making the app accessible on both of them.

Can someone shed some light on this mystery?

Answer №1

For optimal performance, consider launching your server by using the command node server.js(filename) instead of npm start. This will prevent default configurations from being applied. Keep in mind that npm is primarily used for installing node modules, rather than executing the server.

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

Accessing data returned from JSON in JQuery beyond the code block required

Is there a way to access returned JSON data outside of the JQuery getJSON method? For example: var price = ""; $.getJSON("../JSONDeliveryPrice", null, function (data) { price = eval(data.price); }); console.log(price); Unfortunately, this code does not ...

Leverage ajax and grails to dynamically showcase a linked database entry based on a user's selection

Is there a way to select multiple values (IDs) from a database and display them by associated name while saving the ID attached to each selected value (name)? I inquired if this could be done using jQuery, but was advised that Ajax might be a better option ...

Is it possible to create a unique texture transition effect in three.js?

Currently, I am working on creating a model viewer in three.js using opengl. One of the key features I am trying to implement is the ability to dynamically change textures while the model is running. So far, I have managed to achieve this functionality, ...

Different paths lead to the same outcome with express.js by utilizing regex

Is it possible to create a single route that responds to two different URLs? app.get('/:city', sendCityResponse); app.get('/:city/filters', sendCityResponse); Can this be achieved using regex in one route definition? I attempted the ...

The method for viewing stack traces in Express JS server logs

In my tech stack, I'm utilizing Nuxt (Vue), Express.js, and Axios. Encountering a scenario where a REST call fails, exemplified by the code snippet below: axios.get('api/data-test'); The client displays an error message like this: xhr.js ...

Guide on creating a map function with hyphenated fields in mongoDB

While working on a project with Meteor and mongoDB, I encountered an issue. The problem arises when trying to retrieve the value of a field with a hyphenated name using map. How can I work around this obstacle? The specific field in my mongoDB collection ...

What is the process for implementing CORS on a HTTP server designed for a websocket connection, which is operating on the identical port as an Express application?

Currently, I am in the process of setting up a backend using Node and Express. With Express, I have created a simple REST api. In addition to this, I have also set up a websocket.io instance on the same server with the intention of exposing it on the same ...

"Enhance Your Website with Stylish Bootstrap Pop

Hello, I am trying to display a "Loading..." text or spinner image while waiting for the dynamic ajax content to load. Due to the large amount of data that needs to be fetched, it takes approximately 2-3 seconds for the content to fully load. Below is my ...

.Nested ajax repeater with a slideToggle

I'm having an issue with a function that writes the value of a DIV to a cookie. The toggle code works fine, and I can iterate through the repeater elements to determine if a section should be hidden or not. However, when trying to use .show() or .hide ...

Conceal and Reveal every marker on the map

Creating a map using angular to display data on the web page and Google Map is my current project. This is my first major project utilizing Angular, and I have nearly achieved the functionality as planned. I am eager to enhance the site with more user-fri ...

Converting a String to an Integer in JavaScript

I'm having trouble printing the sum in this code // 1. create variables // 2. input numbers into variables [but they are strings] // 3. unable to print the sum // Variables let num = [""]; let num22 = [""]; // Add new number to num ...

What steps are involved in developing a quiz similar to this one?

Check out this interesting quiz: I noticed that in this quiz, when you answer a question, only that section refreshes instead of the entire page. How can I create a quiz like this? ...

"Learn how to extract the image URL from the configuration file (config.json) within the assets folder, and then seamlessly display it within

In my Angular project, I have a configuration file located in the assets folder: { "brandConfig": "brand1", "brand1": {"urlPath": "http://192.168.168.60:8081/mantle-services", " ...

obtain the content of a TextField element

In my React component that utilizes MaterialUI, I have created a simple form with a text field and a button: export default function AddToDo() { const classes = useStyles(); return ( <div style={{ display: "flex" }} ...

Retrieve information from a JSON string

My function is not returning the title of the interval, it keeps returning undefined. Function filterByCategories () { return _.orderBy(this.meetups.filter(item => { console.log('title: ' + JSON.stringify(item.interval.title, n ...

How come the mongoose ref feature is not functioning properly for me when I attempt to reference objects from a different schema?

I'm having trouble accessing the attributes of a store's address, as I keep getting 'undefined'. It seems that the address is only an id, even though I set up a 'ref' in the address schema. What could be causing this issue? H ...

The Simple HTML Dom parser is failing to parse contents on these specific websites

I tried using a basic HTML DOM parser but it's encountering issues when parsing certain websites. include_once 'simple_html_dom.php'; $html=file_get_html('http://www.lapenderiedechloe.com/'); This results in an error message like ...

Route to POST cannot be found

Attempting to post a comment triggers an error that redirects me to the /campgrounds page when I submit it, as indicated in the code below. I'm puzzled about what I'm overlooking; here is the error message: Cast to ObjectId failed for value "5e6 ...

Utilizing the <Link> component in React Router to generate URLs based on the root domain

When users visit goodsite.com, they encounter a link created using react router. The link code snippet is as follows: <TableCell component={Link} to={`happy/${thing.id}`} > {thing.name} </TableCell> This particular link is situa ...

Automatic parsing and formatting of JSON object keys

My form is populated automatically using a script. Whenever the user selects an option from a dropdown, an AJAX request is triggered to an external file (which retrieves data from a database using json_encode) and populates the form fields. Here is the sn ...