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

102
Views
Show 404 when endpoint exists mongoDB

I keep getting a 404 when I am posting to a route. I am using MongoDB, express and React Native. I have created the Schema, actions and the router.

The Schema is below:

const mongoose = require("mongoose");
const Schema = mongoose.Schema;

// Create Edible Schema
const EdiblesSchema = new Schema({
  name: {
    type: String,
    required: true
  },
  price: {
    type: String,
    required: true
  },
  strength: {
    type: String,
    required: true
  },
    purchasedLocation: {
    type: String,
    required: true
  },
  effects: {
    type: String,
    required: true
  },
  strain: {
    type: String,
    required: true
  },
});

module.exports = Edibles = mongoose.model("edibles", EdiblesSchema);

Then the post router is below:

const express = require("express");
const router = express.Router();
const keys = require("../../config/keys");

// Load edibles model
const Edibles = require("../../models/edibles");

// @route POST api/users/edibles
// @desc Add an edible to the users collection
// @access Public

router.post ('/edibles', (req, res) => {
 if (res.status === 200) {
    const newEdible = new Edibles({
        name: req.body.name,
        price: req.body.price,
        strength: req.body.strength,
        strain: req.body.strain,
        purchasedLocation: req.body.purchasedLocation,
        effects: req.body.effects,
    })
    } else {
        return res.status(400).json({ email: "Thats not going to get you high" });
    } newEdible
        .save()
        .then( edibles => res.json(edibles))
        .catch(err => console.log(err))
});


module.exports = router;

Then the finale we have the handleSubmit to send the users info to the api endpoint.

    const handleSubmit = (response) => {
        console.log("EDIBLES", name, strength, price, effects, strain)
        dispatch(setEdible(payload))
        
        if (response === 200) {
            axios
                .post(edibleApi, payload)
                console.log("PAYLOAD", edibleApi, payload, setEdible)
                // navigation.navigate("Dashboard")
        } else {
            console.log("WRONG", edibleApi, payload, setEdible);
            console.log("userEdibles", userEdibles)
        }
        
        
    }

I am really lost with this... Please help! Probably something really stupid to fix it.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The issue was that I was using the wrong endpoint. I worked this out by using the express-list-routes by adding it to my server.js file. const expressListRoutes = require('express-list-routes');

const router = express.Router();

console.log("Now we cooking with gas", expressListRoutes(app, { prefix: '/api/v1' })))

That console.log must be added to the console.log that indicates if your server is running or not....

about 4 years ago · Juan Pablo Isaza Report
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!