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/5aae8f9df40f3924a4b984fIn 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.