problem with mongoose database

0

I have an error that sends me postman

Product is not a function

My code in nodejs is as follows

'use strict'

const express    = require("express"),
      bodyParser = require("body-parser"),
      mongoose   = require("mongoose")

const Product = require("./models/product")

const app = express()
const port = process.env.PORT || 3000

app.use(bodyParser.urlencoded({ extended : false}))
app.use(bodyParser.json())

app.get("/registro", (req, res) => {
  res.send(200, {products : []})
})

app.get("/evento/:eventoId", (req, res) => {

})

app.post("/api/product", (req, res) => {
  console.log("POST /registro")
  console.log(req.body)

  let product = new Product()
  product.mesa                 = req.body.mesa
  product.integrantes.nombre   = req.body.integrantes.nombre
  product.integrantes.mesa     = req.body.integrantes.mesa
  product.integrantes.entradas = req.body.integrantes.entradas
  product.integrantes.usadas   = req.body.integrantes.usadas
  product.integrantes.done     = req.body.integrantes.done

  product.save((err, productStored) => {
    if(err) res.status(500).send({message : 'Error al guardar los datos: ${err}'})
    res.status(200).send({product: productStored})
  })
})

app.put("/evento/:eventoId", (req, res) => {

})

app.delete("/evento/:eventoId", (req, res) => {

})

mongoose.connect("mongodb://localhost:27017/products" , (err, res) => {
  if (err) {
    return console.log('Error al conectar : ${err}')
  }
  console.log("Conexion establecida")

  app.listen(port, () => {
    console.log('Corriendo en el puerto ${port}')
  })
})

and my mongoose model is as follows

"use strict"

const mongoose = require("mongoose"),
      Schema   = mongoose.Schema

const ProductSchema = Schema({
  mesa : Number,
  integrantes : [{
    nombre : String,
    mesa : Number,
    entradas : Number,
    usadas : {type : Number, default : 0},
    done : Boolean
  }]
})


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

I tried to see where the error is but I do not find it

    
asked by salvador Godinez 31.10.2016 в 12:47
source

1 answer

0

To export your module, you put

  

module.export = Product

It must be

  

module.export s = Product

    
answered by 31.10.2016 / 21:10
source