Home > front end >  Cannot get api/path in express
Cannot get api/path in express

Time:04-24

When i try to get /api/file i get status code 404.

Here is my code :

app.js :

...
app.use("/api", require("./routes/users"));
app.use("/api", require("./routes/file"));
app.use("/", require("./routes/login"));
...

routes/file :

...
route.get("/file/:filename", fileController.getFile);
...

module.exports = route;

Here's what I get in postman

postman result

CodePudding user response:

route.get("/file/:filename", fileController.getFile)

You are using the :filename, which is a param - but in your postman request you are looking for a query ?filename=.

Also you are trying to export your routes, using the MVC. You have to use router

const router = express.Router()

router.get('/api..')

module.exports = router;
  • Related