how to fix "can't read property push of undefined" error in Nodejs?
In genres.js, you should import
const router = express.Router();
instead of
const router = express.Router;
Also, the error you mention could be from any push
in your code (without any more info), please specify the stacktrace next time :)
Use const router = express.Router()
instead of const router = express.Router
.
It can be wrong variable name :)
I made a mistake due to intelligence in my quick sample -
Typically signature of a ReST call isrouter.get("/something", (req: any, res: any, next: any) => {response.write("test");response.end();});
Here if you will notice I was using response where as i was suppose to use res
Moreover ensure you have registered your routes usingapp.use(router);