Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

177
Vistas
My backend route is not behaving as it should and not posting anything to MongoDB

I am trying to create a simple CRUD app. I was trying to set up the first backend route but I am stuck and can't figure out what is wrong with my code or what I am missing.

If I try to test the route with Insomnia, it doesn't return any error, but it targets the basic "/" route and returns the console.log('OK') instead of creating an item in MongoDB. Here is my code:

// app.js file

require("./db");

const express = require("express");

const app = express();

require("./config")(app);

const backoffice = require('./routes/backoffice');
app.use('/api/backoffice', backoffice);

app.use('/', (req, res) => {
    res.send('OK')
});

module.exports = app;
// route file backoffice.js

const router = require("express").Router();
const Item = require("../models/Item");

router.post('/backoffice', (req, res, next) => {
    console.log(req.body);
    const {title, description} = req.body;
    
    
    Item.create({
        title,
        description
    })
    .then(response => {
        console.log(response)
        res.status(200).json({message: 'New item added succesfully'})
    })
    .catch(err => res.json(err))
})

module.exports = router;

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda