// Import required modules
const express = require('express');
const mongoose = require('mongoose');
// Initialize Express app
const app = express();
// Middleware for parsing JSON
app.use(express.json());
// MongoDB Connection URI
const mongoURI = 'mongodb://localhost:27017/myDatabase'; // Replace with your MongoDB URI
// Connect to MongoDB
mongoose.connect(mongoURI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log('Connected to MongoDB');
})
.catch((err) => {
console.error('Error connecting to MongoDB:', err);
});
// Basic Route
app.get('/', (req, res) => {
res.send('Server is running and connected to MongoDB');
});
// Start the server
const PORT = 3000;
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)