You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// mongodb-adapter.js'use strict';constexpress=require('express');const{ MongoClient }=require('mongodb');constbodyParser=require('body-parser');constdbConfig={url: 'mongodb://localhost:27017',database: 'angular_backend',};letdb;constapp=express();app.use(bodyParser.json());app.get('/continents',async(req,res)=>{try{constcontinents=awaitdb.collection('continent').find({}).toArray();res.json(continents);}catch(error){console.error('Error fetching continents:',error.message);res.status(500).json({error: 'An error occurred while fetching continents'});}});conststartServer=async()=>{try{constclient=awaitMongoClient.connect(dbConfig.url);db=client.db(dbConfig.database);console.log('Connected to MongoDB database');constPORT=process.env.PORT||3000;app.listen(PORT,()=>{console.log(`Server started on port http://localhost:${PORT}`);});}catch(error){console.error('Failed to connect to MongoDB database:',error.message);process.exit(1);}};startServer();