Unable to fetch data from API (Node JS server)

I am trying to fetch data from my database through my node js, but I keep getting an error of Error: SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON, is there anything I can do to prevent this? My code for the client side is: https://srcshare.io/64f7d7f6a897f132d4fe3c44 My code for the server is:
app.get('/getBlogs', (req, res) => {
supabase
.from('blogs')
.select('*')
.then(blogs => {
res.json(blogs)
})
.catch(error => {
console.error('Error:', error);
res.status(500).send('Error retrieving data from database!');
})
});
app.get('/getBlogs', (req, res) => {
supabase
.from('blogs')
.select('*')
.then(blogs => {
res.json(blogs)
})
.catch(error => {
console.error('Error:', error);
res.status(500).send('Error retrieving data from database!');
})
});
I am unsure of why this is happening, full stack is HTML, CSS, JS (Node & Express), and Supabase (Database)
SrcShare
Easily share your source code with other developers.
2 Replies
Jochem
Jochem15mo ago
That usually means your endpoint is returning html and not json Try logging out the contents of blogs, see what the error is that the server is sending
Daniel Everett
Daniel EverettOP15mo ago
I did console log blogs right in the then statement and it never returned anything, though there is data being stored that can be pulled
Want results from more Discord servers?
Add your server