Postman is showing an error when making a request using Express.js app.get()

Recently, I started working with Express.js and I am using Postman to test my API. When running the code below, I successfully retrieve all members from the object:

// gets all members
app.get('/api/members', (req, res) => {
    res.json(members)
})

For a visual representation of all members, you can check out this image link.

However, when attempting to access a single member from the API using the following code snippet, I encounter a 404 error in Postman:

// get single member
app.get('/api/member/:id', (req, res) => {
    res.json(members.filter((member) => member.id === parseInt(req.params.id)))
})

You can view the specific error message received in Postman by visiting this link.

The provided code includes the full members object that has been transformed into an API:

const members = [
    {
        id: 1,
        name: 'jack',
        email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="402a21232b002d256e232f2d">[email protected]</a>',
        status: 'active'
    },
    {
        id: 2,
        name: 'sheldon',
        email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4a7bcb1b8b0bbba94b9b1fab7bbb9">[email protected]</a>',
        status: 'inactive'
    },
    {
        id: 3,
        name: 'matt',
        email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="04696570704469612a676b69">[email protected]</a>',
        status: 'active'
    },
]

module.exports = members

If anyone can shed light on what might be causing the error, it would be greatly appreciated...

Answer №1

Your specified route is '/api/member/:id' and you are making a request to '/api/members/1'. Please adjust your postman request URL by removing the extra 's'. In other words, use: '/api/member/1'

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

Shader designed to maintain the original lighting of the landscape

Currently, I have a shader set up to mix various textures for my terrain such as grass, sand, and rocks. While the blending is working well, the issue arises with compatibility with Three.js lighting engine. All vertices appear overly bright due to this ...

Having trouble getting the navigation function to work correctly for my ReactJS image slider

I am looking to create a simple image slider that contains 3 images in an array. I want to be able to navigate through the slider using just one function that can move back and forth between images. If you click "next" on the last image, it should bring ...

Is there a better approach to verifying an error code in a `Response` body without relying on `clone()` in a Cloudflare proxy worker?

I am currently implementing a similar process in a Cloudflare worker const response = await fetch(...); const json = await response.clone().json<any>(); if (json.errorCode) { console.log(json.errorCode, json.message); return new Response('An ...

Emerald: Fresh alert for numerous attributes

After updating jade to the latest version, I started seeing a message in the console that says: You should not have jade tags with multiple attributes This change was mentioned as a feature here 0.33.0 / 2013-07-12 Hugely more powerful error reporting ...

Express strangely appends a forward slash to the end of the URL

While working on my website using Node.js and the Express framework, I encountered an unusual issue with a URL. Whenever I click on a link related to the images section, the URL changes to "localhost:3000/images/" with an extra slash added at the end. Ho ...

Having trouble with Vue's $route.push method not working when invoked from a method?

I am currently in the process of creating a search bar for my application using the vue-bootstrap-typeahead autocomplete library. For those unfamiliar, when an option is selected from the suggestions list, it triggers the @hit event which passes the result ...

A recommended design suggestion for optimizing performance when working with node.js, the native MongoDB driver, and Express.js for creating REST APIs

Currently, I am in the process of familiarizing myself with the mongodb native driver in conjunction with nodeJS and ExpressJS. As a newcomer to NodeJS, I appreciate your patience. The data from the UI CLIENT is transmitted to the REST API endpoint, and t ...

Utilizing Parent Scope Variables in AngularJS Directives with Isolated Scopes

I'm feeling a bit lost here (edit: after clarification, my question is "Why isn't the directive recognizing the attributes passed to it?"), even though I thought I had a good grasp on it. I'm having trouble accessing the properties of the pa ...

Attention: The PageContainer component requires React component classes to extend React.Component

I recently started using react-page-transitions in my project and encountered the following warning message: "PageContainer(...): React component classes must extend React.Component." Here is a snippet of my code: import React from 'react'; ...

Retrieving rows from a MySQL table that contain a specified BIGINT from an array parameter

I've encountered a problem with mysql while using serverless-mysql in TypeScript. It seems like my query might be incorrect. Here is how I am constructing the query: export default async function ExcuteQuery(query: any, values: any) { try { ...

Using Jquery ajax, I am interested in storing a single value into a variable for future use in JavaScript

I'm finally able to retrieve a JSON Get request, but I'm struggling with utilizing the information effectively. The array contains 9 items, but I only need one specific value - the id. I want to extract this id and save it in a variable for futur ...

Looking for assistance in switching from using curl to implementing requests

A curl command I have looks like this curl -u 209f734234234j556l45l6j64218ecffb0a900aff998c8e0: -H "Content-Type: application/json" -H "X-Ionic-Application-Id: 123k4j54k" https://push.ionic.io/api/v1/push -d '{"tokens": ["token1,token2,token3"],"notif ...

Executing JQuery asynchronous calls sequentially

Recently delving into the world of Jquery, I've encountered a coding challenge: my code loops through an array and retrieves HTML from an ajax request for each iteration. $.each(arr, function (data) { $.get('/Quote/LoadQuoteItemCost', { ...

jquery toggle for partial visibility not functioning properly

Can jquery sliding functions be used to partially show and hide content? In this scenario, there is a list with 7 items but only the first two are visible initially, while the rest are hidden. The goal is to have all 7 items show when the user clicks to v ...

Verify whether a field has been altered in the post-hook of mongoose for the findOneAndUpdate method

Within the controller, I am utilizing findOneAndUpdate to increment a field. This increment is only executed if the condition for an update query has been satisfied. In the event that the field has been incremented, another model needs to be updated as wel ...

Tips for creating responsive elements with a z-index of 1 in CSS

I have implemented the code provided in a codepen tutorial, but I replaced the world map image with a USA map. However, the dots are not responsive due to the z-index=1 specified on them. I experimented with vh, vw, and percentages, yet when I resize my s ...

Displaying information in form using ajax within the laravel framework

I am currently utilizing ajax to retrieve data from a database. While I am able to successfully retrieve the data on the backend, I am facing difficulties displaying it in the input field below. I have tried writing some code, but it seems that the JavaScr ...

What is the best way to determine if an object.property is defined in Angular 2?

Is there a similar function in Angular 2 to angular.isDefined from Angular 1? I have tried using the safe navigation operator ?., which is only supported in templates. ...

Using es6 map to deconstruct an array inside an object and returning it

I am looking to optimize my code by returning a deconstructed array that only contains individual elements instead of nested arrays. const data = [ { title: 'amsterdam', components: [ { id: 1, name: 'yanick&a ...

Is there a way to shift a background image pattern?

After searching extensively, I came up empty-handed and am seeking guidance on how to achieve a specific effect. Specifically, I am in need of a JavaScript or jQuery script that can smoothly shift a background image to the right within a designated div con ...