Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
why I got this type error not a constructor for javascipt?

I am trying to create a new product.to test whether the result is sent to my mongodb , I input the values in postman.However , I am confused about this error.

This is my Product file

const mongoose = require("mongoose");


const ProductSchema = new mongoose.Schema(
    {
    title: {type:String , required:true , unique:true},
    description: {type:String , required:true},
    img: {type:String , required:true },
    categories: {type: Array , required:true },
    size: {type:Array},
    color: {type:Array},
    price: {type: Number , required:true },
    inStock:{type:Boolean , default:true},

},
{ timestamps: true }
);

module.export = mongoose.model("Product" , ProductSchema);

This is my post code

const router = require("express").Router();
const Product = require("../model/Product")
 //Create new product(testing in postman)
router.post("/", async (req,res)=>{
const newProduct = new Product(req.body);

try{
    const savedProduct = await newProduct.save();
    res.status(200).json(savedProduct);
}catch(error){
    res.status(500).json(error)
}
})

After I send the values in postman, I always encounter this error.

TypeError: Product is not a constructor
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are using

module.export = mongoose.model("Product" , ProductSchema);

it should be

module.exports = mongoose.model("Product" , ProductSchema);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!