Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda