Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

GET method not working on specific route in ExpressJS

When I try to get data using /:user the function is not running inside the specific routing, can anyone figure me out what is the mistake here?

const express = require("express");
const app = express();
const mongoose = require("mongoose");
const {accountSC,catalogSC} = require("./schema");

let dburl = **database url**
app.use(express.json());
mongoose.connect(dburl);

app.get("/catalog", async (req, res) => {
  //some func inside it
});

app.get("/:catalog/:id", async (req, res) => {
    //some func inside it
});

app.get("/:user", async (req, res) => {
    //some func inside it
});

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Basically your /catalog and /:user are the same because of the structure. :user value can be catalog also. So, try out different naming approaches of the routes (/info/:user).

Thank you.

update:
Try out this one.

app.get("/catalog", async (req, res) => {
  //some func inside it
});

app.get("/catalog/:catalog/:id", async (req, res) => {
    //some func inside it
});

app.get("/info/:user", async (req, res) => {
    //some func inside it
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading