Home > Software engineering >  Postman Returning 404 for post route
Postman Returning 404 for post route

Time:02-04

I am new to postman and am trying to do some test uploads to cloudinary. However when i try do some test uploads i am getting status 404 not found in my localhost:5000/api and localhost:5000/api/upload.

Here is my upload.js where i am using router.post:

const router = require("express").Router();
const cloudinary = require("cloudinary");
const fs = require("fs");

//UPLOAD TO CLODUINARY
cloudinary.config({
  cloud_name: process.env.CLOUD_NAME,
  api_key: process.env.CLOUD_API_KEY,
  api_secret: process.env.CLOUD_API_SECRET,
});

//upload image
router.post("./upload", (req, res) => {
  try {
    console.log(req.files);
    res.json("test upload");
  } catch (error) {
    res.status(500).json({ msg: error.message });
  }
});

module.exports = router;

used in server.js:

const productRoutes = require("./routes/productRoutes");
const uploadRoutes = require("./routes/upload");

app.use("/api", uploadRoutes);
app.use("/api/products", productRoutes);

const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));

I dont end up seeing my "test upload message" and postman doesnt seem to be able to connect to it.:

Postman

Any help would be much appreciated

CodePudding user response:

Your route should be /upload not ./upload. I'm not sure whether that is a typo but either way please consider reading the docs on express router.

CodePudding user response:

This seems to be a routing issue from the response returned from postman.

  •  Tags:  
  • Related