going to localhost:5000 give the backend but i cant access the front end when going to…
- User
going to localhost:5000 give the backend but i cant access the front end when going to localhost:3000. Find the error. #PORT=5000 JWT_SECRET=your_jwt_secret_key BACKEND_URL=http://localhost:5000
// App.js import React from 'react'; import { AuthProvider } from './context/AuthContext'; import AppNavigator from './navigation/AppNavigator';
const App = () => { return ( ); };
export default App; // package.json { "name": "fitness-app-backend", "version": "1.0.0", "main": "index.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "description": "", "dependencies": { "@react-native-community/masked-view": "^0.1.11", "@react-native-picker/picker": "^2.8.1", "@react-navigation/native": "^6.1.18", "@react-navigation/stack": "^6.4.1", "axios": "^1.7.7", "bcryptjs": "^2.4.3", "cors": "^2.8.5", "dotenv": "^16.4.5", "express": "^4.21.0", "jsonwebtoken": "^9.0.2", "mongoose": "^8.7.0", "react-native-chart-kit": "^6.12.0", "react-native-dotenv": "^3.4.11", "react-native-gesture-handler": "^2.20.0", "react-native-multiple-select": "^0.5.12", "react-native-reanimated": "^3.15.3", "react-native-safe-area-context": "^4.11.0", "react-native-screens": "^3.34.0", "react-native-svg": "^15.7.1" } } // server.js require('dotenv').config(); const express = require('express'); const mongoose = require('mongoose'); const cors = require('cors');
const app = express();
// Middleware app.use(express.json());
// CORS Configuration app.use(cors({ origin: 'http://localhost:3000', // Frontend URL methods: ['GET', 'POST', 'PUT', 'DELETE'], credentials: true, }));
// Connect to MongoDB mongoose.connect(process.env.MONGO_URI, { // Removed deprecated options as per earlier advice }) .then(() => console.log('MongoDB Connected')) .catch(err => console.log(err));
// Routes app.get('/', (req, res) => { res.send('Fitness App Backend'); });
const authRoutes = require('./routes/auth'); app.use('/api/auth', authRoutes);
const exerciseRoutes = require('./routes/exercises'); app.use('/api/exercises', exerciseRoutes);
const progressRoutes = require('./routes/progress'); app.use('/api/progress', progressRoutes);
// Start Server const PORT = process.env.PORT || 5000; app.listen(PORT, () => { console.log(
Server running on port ${PORT}); });{ "name": "fitness-app-backend", "version": "1.0.0", "main": "index.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "description": "", "dependencies": { "@react-native-community/masked-view": "^0.1.11", "@react-native-picker/picker": "^2.8.1", "@react-navigation/native": "^6.1.18", "@react-navigation/stack": "^6.4.1", "axios": "^1.7.7", "bcryptjs": "^2.4.3", "cors": "^2.8.5", "dotenv": "^16.4.5", "express": "^4.21.0", "jsonwebtoken": "^9.0.2", "mongoose": "^8.7.0", "react-native-chart-kit": "^6.12.0", "react-native-dotenv": "^3.4.11", "react-native-gesture-handler": "^2.20.0", "react-native-multiple-select": "^0.5.12", "react-native-reanimated": "^3.15.3", "react-native-safe-area-context": "^4.11.0", "react-native-screens": "^3.34.0", "react-native-svg": "^15.7.1" } } - Assistant