Node/Express send static file on request

Viewed 7275

I'm really new to node/express and I'm trying to understand how sending static files work. I managed to serve my index file, but I cannot serve other files as response of a GET request.

app.use(express.static(path.join(__dirname, '/client/build')))

app.get('/', (req, res) => {
  res.sendFile(path.resolve(__dirname, '.', 'client/build/', 'index.html'))
  res.end()
})

app.get('/portfolio', (req, res) => {
  const person = req.query.name
  var filePath = __dirname + '/client/build/' + person + '/' + 'index.html'
  res.sendFile(filePath)
  res.end()
})

I found similar questions but nothing seems to work.

The request I send is:

fetch(`portfolio?name=${who}`)
2 Answers
Related