-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (22 loc) · 756 Bytes
/
server.js
File metadata and controls
32 lines (22 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// server.js
const express = require('express');
const path = require('path');
const app = express();
const port = process.env.PORT || 5000;
// Serve static files from the React app
app.use(express.static(path.join(__dirname, 'client/build')));
// Define a route handler for the root path '/'
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
// Example route to log messages from backend to frontend
app.get('/log-to-frontend', (req, res) => {
// Message to send to frontend
const message = 'Backend Connected.';
// Send message as JSON response
res.json({ message });
});
// Start the server
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});