Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot get api/path in express

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

Here is my code :

app.js :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

...
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 :

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;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading