I dont know why my app is returning undefined


When I add this code to my app.js in the express server

app.get('/*', function (req, res) {
res.sendFile(path.join(publicPath, 'index.html')), function(err) {             
   if (err) {                 

The console print the following error when I make a request, except fot the signin page which works good.

    Type error: cannot read
    TypeError: Cannot read properties of undefined (reading '0')
    at Resultados.js:2368:16

Without adding that code lines, the app works okey, except when I refresh the page, because in the browser appear the message cannot get.

Why without the code the app is not returning undefined?


res.sendFile only sends index.html file and other files in your public folder are inaccessible. Serve your public folder like this

const path = require('path')
const publicFolder = path.join(__dirname, 'public');
app.use('/*', express.static(publicFolder))

Answered By – MM2021

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published