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

179
Visualizações
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 à 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