'Cannot get api/path in express

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



Solution 1:[1]

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;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tyler2P