A Guide to Retrieving Parameters and Request Body using Express and Typescript

When I use the PUT method, I encounter this issue:

const createFaceList = (req: Request<{faceListId : string}>, res: Response, next: NextFunction) => {

console.log(req.body.name);
console.log("faceListID = " + req.params.faceListId);

addFacelist(req.params.faceListId, req.body)
.then( result => {
    return res.status(200).json({result})
})
.catch(err => {
    logging.error(NAMESPACE, err.messagem, err);

    return res.status(err.statusCode).json({
        statusCode: err.statusCode,
        message: err.message
    })
})
}

My console output displays undefined values:

undefined
faceListId = undefined

Could someone provide insights on how to resolve this issue? Thank you.

Answer №1

define interface TypedRequestBodyParams<Params, ReqBody> extends Express.Request {
    body: ReqBody,
    params: Params
}

const generateFaceList = (req: TypedRequestBodyParams<{faceListId : string}, {name: string}>, res: Response) => {
    const { faceListId } = req.params
    const { name } = 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

Which Node.js libraries are highly regarded for Json schema validation and serializing into objects?

Which libraries are considered the top choices for validating Json schemas and converting data into objects in Node.js or express.js? ...

What is the best way to send an object array from an express function to be displayed on the frontend?

//search.js file import axios from "axios"; export function storeInput(input, callback) { //input = document.getElementById("a").value; let result = []; console.log(input); if (!callback) return; axios.post("ht ...

Specify markers to suggest a literal object type that is not explicitly stated

Currently, I am developing a function that takes in a configuration parameter, which is essentially an object with a highly variable structure. Depending on the type of configuration provided, the function should output something of equally diverse structu ...

I'm struggling to figure out the age calculation in my Angular 2 code. Every time I try to run it,

Can anyone assist me with calculating age from a given date in Angular? I have written the following code but I keep getting undefined in the expected field. This is Component 1 import { Component, OnInit, Input } from '@angular/core'; ...

Tips for creating unit tests for my Angular service that utilizes the mergeMap() function?

As a beginner with the karma/jasmine framework, I am currently exploring how to add a test case for my service method shown below: public getAllChassis(): Observable<Chassis[]> { return this.http.get('chassis').pipe( merge ...

Uploading documents using AngularJS and Express.js

I'm currently working on a project that involves uploading files using AngularJS and Node.js (with Express.js). To facilitate this process, I am utilizing danialfarid/angular-file-upload. Within my view (built with jade), the code snippet below showca ...

Retrieving selected values from an ngx dropdown list

I am having trouble implementing ngx dropdown list in this way: <ngx-dropdown-list [items]="categoryItems" id="categoriesofdata" [multiSelection]="true" [placeHolder]="'Select categories'"></ngx-dropdown-list> ...

Submit your Node.js test results to Sqhub using GitHub Actions

Currently, I am in the process of developing a new Node.js app with Express using GitHub Actions for continuous integration and deployment. My workflow includes internal re-usable processes for building, testing, uploading to an artifact repository, and de ...

Utilizing Dropzone for file uploads in Node.js, Express, and Angular

I'm running into a bit of trouble trying to get the file recognized on the server side with node.js. Especially when trying to access request data, such as req.files or req.body If anyone has any advice, here are some code snippets: HTML: <form ...

Using Typescript, Angular, and Rxjs to retrieve multiple HttpClients

I am looking to send get requests to multiple endpoints simultaneously, but I want to collect all the responses at once. Currently, this is how a single endpoint request is handled: public getTasks(): Observable<any> { this.logger.info('Ta ...

Best practices for implementing the map function with TypeScript

I'm currently working on mapping types in a DB using the Map function in JavaScript. This is my first time trying to do this, and I'm eager to learn but I've hit a roadblock. Here is the structure of the DB: const db = { data: [ { ...

Unable to establish a connection with the default port on Mongo DB while utilizing Node.js

I am new to using Node.js and I'm trying to establish a connection with MongoDB in my Node.js application, but I'm encountering issues. Here is the code snippet: var mongo = require("mongodb"); var host="127.0.0.1"; var port=mongo.Connection.DE ...

During Google login, passport.authenticate mistakenly inserts a null object into the request

I've implemented Google authentication with Express and Passport for my application. Below is the route I'm using: const googleAuthCallback = function(req, res) { if (req.user._id) { if (abc()) { return res.redirect('/app' ...

Transferring information from a React Native app to a Node.js server using Express

Looking for advice on transferring data between React Native and Node.js (Express)? I'm currently developing an app using React Native and Node.js with Express, but struggling to establish communication for data exchange. Any tips would be greatly ap ...

Nextjs REACT integration for self-service registration through OKTA

Attempting to integrate the Okta SSR feature for user sign-up in my app has been challenging as I keep encountering this error message: {"errorCode":"E0000060","errorSummary":"Unsupported operation.","errorLink& ...

The toggle button requires two clicks to activate

I created a toggle button to display some navigation links on mobile screens, but it requires two clicks upon initial page load. After the first click, however, it functions correctly. How can I ensure that it operates properly from the start? Below is t ...

Sending data with an Http POST request in Angular 2

I'm having difficulty with a POST request that I am trying to make: sendRequest() { var body = 'username=myusername&password=mypassword'; var headers = new Headers(); headers.append('Content-Type', 'applicat ...

Create a specific definition for a packaged item with limited access

As I worked with a package that lacked types, I took the initiative to create a type definition for it. The specific package in question is react-date-range. In order to accommodate this new type definition, I established a directory where it could be loca ...

Can Okta be integrated with mysql databases?

Is it possible to integrate Okta with MySQL? While I understand that Okta is used for securely storing user accounts, I would also like to have an Id for the users in my own database. ...

Dropzone and Typescript: A Powerful Combination

I'm currently working on an application that utilizes Dropzone 4.3 and is built with Typescript. Previously, we needed to set a global variable on Dropzone for everything to work smoothly. Dropzone.autoDiscover = false; These are the node packages I ...