What causes the log output to appear twice when using both app.get() and app.use()?

My Express web server is very basic and includes the following code:

var app = module.exports = express.createServer();
app.get('/:user', function(req, res) {
    console.log('GET');
});

app.param('user', function(req, res, next, id) {
    console.log('PARAM');
    next();
});
app.listen(3000);

Whenever I navigate to http://localhost:3000/MyName, I notice that the console displays the output twice:

PARAM
GET
PARAM
GET

I am curious as to why this behavior is occurring. Can anyone explain?

Answer №1

It is probable that the browser initiated a secondary request to fetch the favicon (

http://localhost:3000/favicon.ico
).

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

Dealing with Worker Process Response in Node.js

In my endeavor to develop a service incorporating the Command Query Responsibility Segregation Pattern (CQRS) in NodeJs, I have devised a specific strategy for segregation: I am setting up distinct workers for querying and executing commands These worker ...

When utilizing a clone in a Draggable and Droppable scenario, the data/attribute is obtained from the

Currently, I am struggling with retrieving data/attributes from the original item when using jQueryUI draggable/droppable to move rows between tables. I have set helper: 'clone' but am finding it difficult to access any data from the dragged item ...

Using AJAX to load a PHP file in CodeIgniter is a great way to

I'm a beginner in the world of web development and I need help with loading my PHP file containing HTML content to update the span element. My framework of choice is CodeIgniter. Every time I try, I encounter an error. Below is my JavaScript code: ...

Switching from React version 15.6.2 to 16 results in disruptions to the functionality of the web

Currently, I am encountering an issue where none of my index.js files are rendering. After using the react-scripts to build my web application in version 16.2.0, I receive an error stating that r.PropTypes is undefined when trying to access the localhost a ...

Adjusting the backdrop hues

My goal is to change the background colors of my website by cycling through all possible combinations. However, I'm encountering issues with my code and can't figure out what's wrong. var red = 0; var green = 0; var blue = 0; do { do ...

Tips for enhancing undo/redo functionality when working with canvas drawings in React

Currently, I am working on implementing undo/redo functionality for html-canvas drawing on medical (.nii) images in a React application. The images consist of slices stored in a Uint8ClampedArray and usually have dimensions around 500 (cols) x 500 (rows) x ...

Updating state from a child component: facing the dilemma of potentially encountering an infinite loop or a warning

I have encountered an issue while trying to update the state of a parent component from one of its children. The child component runs a timer function using useEffect, and I passed a handler from the parent to the child via props to call it when a certain ...

tips for accessing the output of a function within an object using TypeScript

I have developed a TypeScript module that simplifies the process. This function takes an object as input and executes all the functions while updating the values of the corresponding properties. If any property in the object is not a function, it will be ...

There seems to be an issue with the React 15 setState function not working on

My react setState after action isn't functioning properly. handleChange = () => { this.setState({foo: 'bar'}); < - it's working console.log('hellow') < - not working, console is clean } I have double-check ...

Enhance the mongoose update functionality to verify existing fields prior to adding new ones

I have successfully fixed the duplicate error and updated my route to add an episode object to the episodes array. However, I am still struggling with implementing a check in the query to ensure that there are no season_number and episode_number combinatio ...

On Internet Explorer 9, the window.open function is causing a new window to open up with

I am having an issue with redirecting my form to another page in a new window using window.open(). The problem I'm encountering is that when the new window opens, it appears blank and the original browser window redirects to the intended page for the ...

Adjust the camera in Three.js to move in a straight line towards the right

Seeking assistance with moving the 3D camera in a linear motion. The current code I am using rotates the camera around the object, but I am looking to move the camera alongside the object instead. Desired Outcome: https://i.sstatic.net/RGMxP.png Current ...

Printing form data with values in CodeIgniter

Recently, I tackled the challenge of creating a page with multiple forms in view using codeigniter. My goal is to implement a popup window for printing the data from these forms, complete with a print button. However, I am struggling with the process of ...

Is it possible for me to pass a reference to a specific object's instance function?

Can JavaScript allow you to pass a function reference to a specific object's function, similar to what can be done in Java? Let's take a look at this code snippet: _.every(aS, function (value) { return exp.test(value); }); What if we want ...

Fetch a document from a NodeJS Server utilizing Express

Is there a way to download a file from my server to my machine by accessing a page on a nodeJS server? I am currently using ExpressJS and I have attempted the following: app.get('/download', function(req, res){ var file = fs.readFileSync(__d ...

When PHP echo of json_encode triggers an error, AJAX status 200 will be raised

Despite everything running smoothly in the program below, an AJAX error is triggered: javascript: var data = { email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="026f6742656f636b6e2c616d6f">[email protect ...

Using SOAP in a JavaScript-exclusive setting

I'm looking into utilizing SOAP as the backend services to supply data for my application. My query pertains to the feasibility of implementing this with just a JavaScript framework like Ember or Angular, without utilizing server-side languages such ...

Seamless transition between different camera perspectives

I'm currently working on creating seamless transitions between different camera viewpoints by using cubes to represent each perspective. The transition is functional for the first click, but subsequent clicks abruptly jump to the designated cube witho ...

I am looking to create a nested post request within a Node.js and Express application. What is the best way

Successfully implemented push notifications in my application. However, encountering an issue: I'm looking to save all sent notifications in my database. The code snippet is as follows: var FCM = require("fcm-node"); const express = req ...

Displaying the focus icon on the active tab using Angular Material

I am currently utilizing Angular material to dynamically generate tabs in my HTML code. I'm trying to display a drop arrow icon on the active or selected tabs, but I am facing some challenges with the implementation. Below is the code snippet I have ...