Search code examples
javascriptnode.jsexpressfeathersjs

Can't serve static files with feathersjs express app


I need to serve some image files from my app which are on a root folder called uploads.

I am setting the middleware on the same level as my folder. The code currently looks like this:

const express = require('@feathersjs/express')
const Path = require('path')

app.use('/uploads', express.static(Path.join(__dirname, `uploads`)))

If I try to do fetch a using localhost:[MY_PORT_NUMBER]/uploads/myImage.jpg I am currently getting a 404 and in the logs it is just getting the NotFound: Resource not found message.

What am I doing wrong?


Solution

  • Try this:

    app.use('/uploads', express.static(Path.join(__dirname, '/../uploads')));