I successfully set up my first basic server using express, however I am encountering an issue when trying to fetch JSON data from a file called data.json:
Here is the code for the server:
const express = require('express')
const app = express()
const port = 5000
app.get('/data', (req, res) => res.send('data.json'))
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
The server.js file and the data folder containing the data.json file are located at the same level.
Although the server seems to be functioning properly, I keep receiving the error message Cannot GET /
.
Can someone please help me identify what might be wrong with my code?