I am working on an app where the backend is currently running on localhost:8000, but I need it to run on port 3000. Specifically, I am using an express server for this example. How can I configure it to run on the desired port?
Below is my current server.js file:
const express = require('express');
const cors = require('cors');
const path = require('path');
const testimonialsRoutes = require('./routes/testimonials.routes');
const concertsRoutes = require('./routes/concerts.routes');
const seatsRoutes = require('./routes/seats.routes');
const app = express();
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(express.static(path.join(__dirname + '/client')));
app.use(cors());
app.use('/api/', testimonialsRoutes);
app.use('/api/', concertsRoutes);
app.use('/api/', seatsRoutes);
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/client/NewWaveFest/public/index.html'));
});
app.use((req, res) => {
res.status(404).json({ message: 'Not found' });
});
app.listen(process.env.PORT || 8000, () => {
console.log('Server is running on port: 8000');
});