-
-
Notifications
You must be signed in to change notification settings - Fork 488
Closed
Labels
Description
I am consistently getting an error running node server.js but I am having trouble debugging the code.
My Code
///////////////////////////////////////////////////////////////////////////////////////
var express = require('express')
var cors = require('cors')
var app = express()
///////////////////////////////////////////////////////////////////////////////////////
app.use(cors({
origin: 'http://localhost:3001',
methods: ['GET', 'POST'],
allowedHeaders: ['Content-Type']
}));
///////////////////////////////////////////////////////////////////////////////////////
app.get('/api/endpoint', cors(), function (req, res, next) {
const data_in = {message_0, message_1};
res.json(data_in);
})
///////////////////////////////////////////////////////////////////////////////////////
app.post('/api/endpoint', cors(), function (req, res, next) {
const data_out = {message_2, message_3, message_4, message_5};
res.json(data_out);
})
///////////////////////////////////////////////////////////////////////////////////////
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});
///////////////////////////////////////////////////////////////////////////////////////
I am running locally using a react framework. Upon running node server.js, my console returns:
Server running on http://localhost:3000
But, when I go to http://localhost:3000 in my browser I get an error: Cannot GET /. I went into developers tools and found the uploaded HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /</pre>
</body>
</html>
In the browser, the only console errors I am seeing are:
Failed to load resource: the server responded with a status of 404 (Not Found)
GET http://localhost:3000/ 404 (Not Found)
I am struggling to debug the code with the information provided. Any advice or suggestions would be appreciated.