I'm curious about the origin of this.on event handler. Is it part of a particular library or framework?

While casually perusing through the application.js file in the express source code, I stumbled upon this interesting piece of code.

I'm curious about the origin of this '.on' event. Is it part of vanilla JavaScript or is it a feature provided by some library for handling events?

 this.on('mount', function onmount(parent) {
        // inherit trust proxy
        if (this.settings[trustProxyDefaultSymbol] === true
          && typeof parent.settings['trust proxy fn'] === 'function') {
          delete this.settings['trust proxy'];
          delete this.settings['trust proxy fn'];
        }
    

Link to Code

Answer №1

app, the application prototype (found in /lib/application.js and utilized in /lib/express.js), is endowed with the functionalities of an EventEmitter, a core Node.js type.

Within the current iteration of the codebase, this process occurs within /lib/express.js through the following line:

mixin(app, EventEmitter.prototype, false);

The function mixin originates from the merge-descriptors module.

Answer №2

According to the Node JS documentation:

The EventEmitter class is responsible for handling events emitted by objects in Node JS. By using the eventEmitter.on() function, one can attach multiple functions to listen for specific named events triggered by an object.

In this context, the instance of express app represented by this, as noted in this link, inherits all methods from EventEmitter, including the on() method.

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

Does the CSV stream parser (PapaParse) cause rendering delays?

Currently, I am utilizing papa parse to fetch csv streams from my backend in order to visualize data. However, I have observed that while it is successfully invoking the callback for the data chunks, it is also causing rendering issues. I am attempting to ...

JavaScript encountering a NaN value

I'm encountering an issue where I am receiving a NaN when attempting to summarize columns of a report. Additionally, my query is only retrieving 1 row of data, but the grid is displaying 2 rows. Does anyone have any suggestions on how to resolve this ...

Is there a way to transmit a value from a page item on the client side to the server side in Oracle Apex without needing to submit the form?

I implemented a JavaScript function to capture the unique ROWIDs of selected rows in the GRID and send them to a specific page item. var gridView = apex.region("emp").call("getCurrentView"), selectedRecords = gridView.getSelectedRec ...

What is the process for obtaining a client-side cookie using next.js?

I'm currently facing an issue where I can't seem to maintain a constant value for the isAuthenticated variable between server-side and client-side in next.js. In my setup, I am using a custom app.js file to wrap the app with Apollo Provider. The ...

Troubleshooting a React JS and material-ui issue

Having an issue with material-ui integration in reactjs. Attempting to render a FlatButton, but encountering the error message: TypeError: _context$muiTheme is undefined As a newcomer to reactjs, I'm unsure of where the problem lies. Below is my code ...

Firefox MediaSourceExtension now has enhanced mp3 support

Currently exploring the integration of adaptive and progressive audio streaming in the browser without the need for plugins. MSE is the HTML5 API that I've been anticipating, now available in FF 42. However, I'm encountering issues with audio fo ...

Tips on how to modify database records rather than generating new ones

Currently, my team is developing a web application that utilizes wearables to monitor vital parameters. As part of our integration testing, we are using a Fitbit device. The app itself is built with Angular and JavaScript, while the database is hosted on C ...

Setting an ID attribute with EditorFor

I have been working with a template for Views and utilizing a lot of JQuery to extract input from an EditorFor. Due to this, I prefer sticking with my current setup using EditorFor instead of something like <input type="text"> I recently added a dat ...

What sets apart elem['textContent'] from elem.textContent?

When dealing with a HTMLElement in JavaScript, is there any distinction between the following lines of code: elem['textContent'] = "Test"; versus elem.textContent = "Test"; This question arises when setting the text content of an HTMLElement. ...

Unable to locate module 'hbs' in the directory for express-handlebars

Every time I attempt to utilize the express-handlebars view engine for express, an error keeps popping up. The error message reads as follows: Error: Cannot find module 'hbs' at Function.Module._resolveFilename (module.js:538:15) at Func ...

Endless [React Native] onFlatList onEndReached callback invoked

Attempting to create my debut app using ReactNative with Expo, I've hit a snag with FlatList. The components are making infinite calls even when I'm not at the end of the view. Another issue might be related; across multiple screens, the infinite ...

Having difficulty integrating a Hangout button using APIs on my webpage

I'm having some trouble adding a basic Hangout button component to initiate Google's Hangout. I've been following the steps outlined on the Google Developer page, but despite my efforts, I can't seem to resolve the following issue: Fai ...

The scrollIntoView feature of JavaScript is unable to scroll an element to the exact top of the scrolling

Vue is the framework I am utilizing for my current project. JavaScript: let captureElement = document.getElementById('tag' + (index - 1)); if (captureElement) { captureElement.parentNode.scrollIntoView({behavior:"smooth",block: "start", inl ...

Vue.js custom confirmation component failing to open within v-menu

I am having trouble displaying a confirmation component every time a button in the header is clicked. Currently, it only opens when clicking elements outside of the dropdown using v-menu. App.vue <template> {{isConfirmDialogVisible}} <div cla ...

When utilizing useEffect in Next.js, an error may occur stating that the window is

It seems like there is a challenge with executing script code server side in next.js 13 when it needs to be executed client side. Currently, I am trying to implement the bulma calendar found at When importing the required library: import PasswordStrengthB ...

Having trouble getting Passport.js middleware to redirect properly with AJAX requests?

I am transferring some data from Javascript to Node through AJAX and JQuery. In Node, I have configured a post request and added a middleware to verify if the user is logged in (redirecting them to the login page if not). However, the res.redirect() in my ...

What is the best way to end a session?

I'm having trouble destroying a session after the user logs out. The current code I've used doesn't seem to be working as expected. Despite being able to print the console.log() from the logout route, the session remains active. Here is th ...

Exploring ways to store session data in Next.js 13 with Supabase for seamless persistence

Encountering an issue with next-auth. Upon logging in, the result shows ({error: 'SessionRequired', status: 200, ok: true, url: null}), despite having an active session. The console also displays this error message, which I believe may be related ...

Combining jQuery form validation with a PHP script on a single webpage

After implementing jQuery form validation and redirecting using the function btn_onclick() { window.location.href = "http://localhost/loginprivate.php";} from index.php to loginprivate.php, my web app's PHP script is not being executed. The user is re ...

Is it possible to determine if NPM install is functioning correctly in various situations or does it vary?

npm init is the first step to start a project I have specified axios: "~1.2.4" in my package.json file When I execute npm install, it installs version 1.2.6, updating to the latest patch as expected If I use ^1.2.4 in package.json and run npm in ...