Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!