Search code examples
node.jsexpresstype-assertion

How to check if object is an instance of Express.Router?


Can anyone tell me how to do this correctly?

import {Router} from 'express';
import assert from 'assert'

let routerInstance = new Router();

assert(routerInstance instanceof Router); // this is throwing an error

Thanks for the help!


Solution

  • With a little experiment, I did this instead:

    Object.getPrototypeOf(routerInstance) == express.Router; //this returns true