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

The Slack Bot is having trouble downloading files from direct messages, but it is successfully downloading them when uploaded to a channel

I have developed a program to retrieve files using a code snippet provided by a Slack bot. Below is the code: var https = require('https'); var fs = require('fs'); var downloadFile = function (url, dest){ var slug = url.split(&apos ...

Unable to open javascript dialog box

One issue I encountered involves a jqGrid where users have to click a button in order to apply any row edits. This button is supposed to trigger a dialog box, which will then initiate an ajax call based on the selected option. The problem lies in the fact ...

Is it possible to assign multiple ID's to a variable in jQuery?

I am currently using a script for a slider known as Slicebox, and in order to have different image sizes for mobile and desktop views, I need to duplicate the feature on my website. Although it's not ideal, I really like this slider and want to explo ...

Implementing the onClick function for the correct functionality in a ReactJS map component

I have designed a mockup and now I am trying to bring it to life by creating a real component. View my component mockup here Starting with something simple, I created 3 buttons and an array. However, when I click on any button, all features are displayed ...

Assistance with Jquery for toggling checkboxes when labels are clicked

I'm currently working on a feature that allows for checking and unchecking checkboxes upon label click. You can find my Jsfiddle here: http://jsfiddle.net/PTAFG/1/ The HTML structure cannot be altered Here is the snippet of my HTML: <div style= ...

Can you provide guidance on configuring Express Gateway to establish secure connections with my services?

Currently, I have set up express-gateway to connect with a backend service on my machine through a unique port. The setup is functioning properly as the gateway acts as a proxy, conducting security checks and jwt authentication. This ensures that only au ...

Tips for Converting a JavaScript Array into JSON

I am dealing with data structured like this: "team": "Yankees" "players": ["jeter", "babe ruth", "lou gehrig", "yogi berra"] In my code, I extract these values from a form where they ar ...

Tips for simulating next/router in vitest for unit testing?

Struggling with creating basic tests for our Next.js application that utilizes the useRouter() hook, encountering errors when using vitest. In search of solutions to mock next/router for unit testing in conjunction with vitest. ...

Struggling to make npm and sqlite3 function properly on MacOS Catalina

Struggling with npm package installation in a project directory on my Mac has proven to be quite the challenge. Each attempt at a simple npm install results in perplexing errors that I can't seem to grasp. The hurdle seems to center around specific p ...

What is the best method for adjusting the text size within a doughnut chart using react-chartjs-2?

Is there a way to adjust the text size within the doughnut chart using react-chartjs-2? I find that the center text appears too small. https://i.stack.imgur.com/QsI0V.png import React, {Fragment} from 'react'; import Chart from 'chart.js&a ...

The controller is not receiving the isolated scope value

I have implemented angular-slider.js on a webpage where a server request is triggered upon changing the slider's value. I am looking to delay this action until the user releases the mouse button, specifically during onmouseup event. Incorporating thi ...

Are you experiencing issues with the .submit() function when used in conjunction with other

Currently, I am working on a survey form that incorporates JQuery to dynamically display or hide fields based on user selections. //FORM CONDITIONALS: This script is responsible for hiding all the helpfulness radios and only displaying them when "Yes" fo ...

Can pagination numbers in Jquery DataTable be configured based on the total records returned by the server and the number of records chosen by the user?

I am currently diving into the world of DataTable.js, a jQuery plugin, and working hard to articulate my questions effectively. For my specific needs, I need to retrieve only 10 records initially whenever an AJAX request is made, even if there are 100 rec ...

Using Javascript and Node.js to send a JSON request

While browsing through this particular question, I came across a method in node.js to distinguish between html requests and json requests: app.get('/route', function (req, res) { if (req.is('json')) res.json(data); else if (req ...

Repairing the Performance of the 'Save' Feature

Can the 'Save' button in my code save team assignments for players selected using drag and drop? I'm considering using localStorage, but unsure about implementation. Note: To run the code properly, copy it as an HTML file on your computer. ...

Strategies for avoiding the issue of multiple clicks on a like button while also displaying an accurate likes

My latest project involves creating a Like button component that features a button and a likes counter text field. The challenge I am facing is that each time I click on the button, it toggles between like and dislike states. However, if I rapidly press ...

Tips for directing the scroll according to the current selection class

I am attempting to focus the scroll based on the selected class when clicking on the previous and next buttons. How can I achieve this functionality? Please review my code on https://jsfiddle.net/kannankds/bcszkqLu/ <ul class="kds"> <li>tile ...

ajax is triggering the error handler

I am currently developing a web application and I am trying to send data from a PHP controller to JavaScript. After conducting some research, it seems that the most efficient way to accomplish this is by utilizing Ajax and Json. However, I am encountering ...

Why is JSON ParseError still returned by jQuery .ajax call despite JSON being seemingly correct?

Despite having valid JSON on jsonlint.com, I'm encountering a ParseError. Below is the jQuery code snippet: $.ajax({ url: path, type: 'GET', data: {}, cache: false, dataType: 'json', contentType: 'app ...

What is the best way to display a Base64 image in a server-side DataTable?

This HTML code is designed to load server-side data into a table. The data is retrieved from the controller using AJAX requests. <script type="text/template" id="tablescript"> <td><%=Name%></td> <td><%=PhoneNumber%> ...