Giter Club home page Giter Club logo

Comments (4)

wesleytodd avatar wesleytodd commented on May 1, 2024

Hi @kisshore04, can you post more clear code examples? Ideally a single file/code block which illustrates your setup in its entirety? These partial lines do not help anyone answer your question. If it turns out this is a bug or in need of better docs or something I will leave this open awaiting more information, but we do not provide technical support so if that is what you are looking for you might have better luck on StackOverflow or Reddit.

from express.

joeyguerra avatar joeyguerra commented on May 1, 2024

@kisshore04 have you tried router.param(‘department_id’)? Without the colon. https://expressjs.com/en/4x/api.html

from express.

kisshore04 avatar kisshore04 commented on May 1, 2024

@kisshore04 have you tried router.param(‘department_id’)? Without the colon. https://expressjs.com/en/4x/api.html

yeah i have always used router.param('department_id'); without the colon. I mistyped it in here.

from express.

kisshore04 avatar kisshore04 commented on May 1, 2024

Hi @kisshore04, can you post more clear code examples? Ideally a single file/code block which illustrates your setup in its entirety? These partial lines do not help anyone answer your question. If it turns out this is a bug or in need of better docs or something I will leave this open awaiting more information, but we do not provide technical support so if that is what you are looking for you might have better luck on StackOverflow or Reddit.

I apologize for the confusion in my previous message. Here is the revised version of the issue. I'm encountering an issue with the router.param function in Express.js. I have a setup where I'm expecting a callback function (myCallback) to be executed when there is a request to the route /api/department/:department_id/class/:id. However, during testing, I found that myCallback is not being invoked.

Here's the relevant code from app.js:

const express = require("express")
const app = express()

app.use("/api/department/:department_id/class", classRouter);
app.use("/api/department/", departmentRouter);


And from class-router.js:

const express = require("express")
const router = express.Router({mergeParams: true})

router.param("department_id", myCallback);

router.get("/:id", controllerFuntion)

Interestingly, in my department router where I have a similar setup, the middleware is executing successfully. The route to this is: /api/department/:department_id.

const express = require("express")
const router = express.Router({mergeParams: true})

router.param("department_id", myCallback);

router.get("/:department_id", getDeptDetails)

I've used the {mergeParams: true} option while creating the router and I have not used the colon (:) when I call the router.param() function.

Any help on why myCallback is not running when the request is coming to the nested route would be greatly appreciated.

from express.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.