DELETE Not Found with Postman in APIREST NodeJs with Mongo and Mongosoe

0

How about classmates? I'm working on an api rest with NodeJs, MongoDB and Mongoose, but when implementing DELETE by Id, the postman sends me an error     

Cannont DELETE /api/product/5aae8f9df40f3924a4b984f
In the status of the Postman sends a 404 not found My code in the index.js for the delete, is as follows.
The resource could not be found but may be available again in the future

My code in the index.js for the DELETE is:

'use strict'

const express = require('express')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')

const Product = require('./modelos/producto')

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

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

app.delete('api/product/:productId', (req, res) => {

let productId = req.params.productId

Product.findById(productId,(err, product) => {
    if (err) res.status(500).send({message: 'Error al borrar el producto ${err}'})
    product.remove(err => {
        if (err) res.status(500).send({message: 'Error al borrar el producto ${err}'})
             res.status(200).send({message: 'Producto eliminado'})
        })
    })
})

My POST and GET work perfectly and in GET I call by ID with no problem. Thanks in advance colleagues.

    
asked by CobriiMusic Sz 18.03.2018 в 21:24
source

1 answer

0

In the path missing the "/" in front of api, it would be:

app.delete('/api/product/:productId', (req, res) => {
    
answered by 29.04.2018 в 01:03