Skip to content
Advertisement

Node.JS – Product is not a constructor error

My code is as follows and gets me "message": "Product is not a constructor" using postman. Router seems to be properly configured but now I don’t know what is the issue. File product constructor is placed at the right direction. When running node server I get no errors in terminal.

product constructor

JavaScript

Router for POSTS

JavaScript

Advertisement

Answer

It should be module.exports (doc), not module.export:

JavaScript

Right now your module essentially exports a default value (an empty object).


As a sidenote, Schema is expected to be used as a constructor. While the function itself is written the way it’ll recall itself with proper syntax if used without new:

JavaScript

… you can both avoid this (albeit miniscule) loss of performance and, what’s more important, show the actual intent clearly:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement