What could be the reason behind receiving a Req.Req (Nested request) when using this specific configuration in Express?

IMPORTANT NOTE: If you are experiencing issues with nested requests or responses, make sure to check the parameter order or utilize the express.router({mergeParams: true}) option.

It seems like my requests are being encapsulated by an additional object request.

In order to access 'req.body', I have to do it like this -> req.req.body. Is this due to my configuration?

I am running an express server with the following setup:

import express from 'express';
import routes from './routes.js';

const app = express();

app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use('/api', routes);

server.listen(80);

This is the content of routes.js file:

import express from 'express';
import webhooksRoutes from './controllers/Webhooks/webhooksRoutes.js';

const routes = express.Router();
routes.use('/webhooks', webhooksRoutes);

This is the content of webhooksRoutes.js file:

import express from 'express';
const userRoutes = express.Router();

userRoutes.post('/orders', orderWebhooks);

This is the content of orderWebhooks.js file:

const wirecardOrdersWebhooks = (res, req) => {
    // The actual request received by the server is located in res.res
    const realReq = req.req;
}

Answer №1

If you want the req before the res, make sure to pass it in as the first argument;

const handleWebhooks = (req, res) => {
   // The actual request sent to the server is stored in res.res
   const actualRequest = req.body
}

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

What is the behavior of a variable when it is assigned an object?

When using the post method, the application retrieves an object from the HTML form as shown below: code : app.post("/foo", (req, res)=> { const data = req.body; const itemId = req.body.id; console.log(data); console.log(itemId); }) ...

Header Express does not contain any cookies, which may vary based on the specific path

In my express.js app, I have two controllers set up for handling requests: /auth and /posts. I've implemented token authorization to set the Authorization cookie, but I'm encountering an issue when making a request to /posts. The request goes th ...

What is the best way to send an array of objects to a Jade template?

I'm looking to retrieve an array of objects from MongoDB and pass it to the client... Here is an example object: var objeto_img= { name:'name of the file', ...

Encountered a problem when attempting to launch the React application

[Issue encountered while attempting to launch myfirstreact with npm start] Hello everyone, I am a beginner in the world of React. I am currently facing a problem when trying to run myfirstreact using npm start. Despite receiving an error message pointing ...

Error message: "Encountered an unhandled promise rejection while

I encountered the following error within a catch block: Error: Unhandled promise rejection. This error occurred either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). Here is ...

The error message in node.js states: "Property 'user_id' is not readable."

I recently started working with Android Notifications and have encountered a persistent error despite trying various solutions. Any assistance would be greatly appreciated. Thank you in advance. const functions = require('firebase-functions'); c ...

Utilizing an NPM Mirror: A Comprehensive Guide

Oh no, the npm registry is experiencing issues once more, causing havoc with executing npm install. Query: What is the alternative method for using npm to fetch packages from npm mirrors? Can you suggest any reliable npm mirrors? ...

Struggling with slow response times when interacting with Firestore in Firebase Cloud Functions?

I am currently experiencing performance issues with a simple Cloud Function in Firebase. This function is responsible for taking JSON data through an HTTP POST request and storing it in a Firestore collection. Despite being assigned 512MB of memory, the pe ...

Is NoSQL supported by the MySQL Community Edition?

I have decided to dive into learning and developing a Node.js application with SQL. I am aware that the MySQL Enterprise Edition offers support for NoSQL, but I'm curious if the community edition also supports NoSQL or if I need to invest in the enter ...

Having trouble establishing a connection to the mlab Database from my local machine

As I attempt to establish a connection between my localhost and the mlab database using node.js, I encounter an issue. The URL I am using is mongodb://username:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ff8f9e8c8c88908d9bbf ...

Error in node: nodenv could not locate any specified version for use

Following a successful installation of Node, I encountered the following error message: $ npm nodenv: couldn't find any version specified for use $ node nodenv: couldn't find any version specified for use Does anyone have insight into where thi ...

"Encountering issues with node-gyp rebuild error during installation of node-memwatch on CentOS 6

While attempting to install memwatch using "npm install memwatch", I encountered the following error: The server is running CentOS6 with Python 2.6.6 installed. [email protected] install /home/[[username]]/public_html/sockets/node_modules/memwatch ...

How can I manage asynchronous calls when querying Mongoose for each element in an array using Express?

Having trouble with the post method below because of a mongoose async issue. The code res.send(suggestions) is being executed before Expense.findOne.exec. app.post('/suggestions', async function(req, res) { const suggestions = await req.body ...

Guide to establishing a connection between Reactivesearch and an external Elasticsearch cluster

Trying to link my reactive search app with an external Elasticsearch provider (not AWS) has been a challenge. The provider does not allow any modifications to the Elasticsearch cluster or the use of Nginx in front of it. In accordance with the reactive se ...

I noticed that my node.js application is intermittently throwing an Unhandled 'error' event when processing write requests, shortly after I configured it to run behind Nginx

Having been successfully running node.js(0.8.20 and 0.9.10) on Windows Server 2012 for weeks without any issues, I recently added Nginx(1.2.6) to the mix. However, after configuring Nginx as follows: #user nobody; worker_processes 1; #error_log logs/e ...

Issue with Node.js inability to retrieve Mongoose find query results

Currently learning Node.JS and facing an issue that I can't seem to resolve. My project involves creating a restful service for retrieving data from mongo. app.js var database = require('./database.js'); ... app.get('/metadata', ...

Encountering a Typescript issue with mongoose

Working with node.js and various email addresses, I encountered a compile error: TS2345: Argument of type '(error: any, document: any) => void' is not assignable to parameter of type '(err: any) => void'. This error occurs at the l ...

Avoid the nesting of node_modules within node_modules

When executing npm install, specific node packages with nested node modules are installed. For example: -node_modules -packageA +js -node_modules <--- should be removed/ignored +jquery -packageA-sub1 +j ...

How come running `npm install <folder>` results in installing different dependencies compared to `npm install lib`?

My current project, project1, relies on <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5221262b3e37367f313d3f223d3c373c262112667c6">[email protected]</a>. When attempting to integrate project2 into project1 as a ...

Various choices are available for designing a live notification system

Trying to figure out the most effective architecture for developing a real-time notification system. My app's journey: A React app triggers a POST API in Node, which updates the notification table. Here's where I'm stuck: Should another ...