I've been working on a mini URL shortener project using JavaScript, Express, and MongoDB, but I've encountered some errors when trying to launch my local server and connect to MongoDB! Here's a snippet of my code:
const express = require('express')
const mongoose = require('mongoose')
const ShortUrl = require('./models/shortUrl')
const app = express();
mongoose.connect('mongodb://localhost/urlShortener', {
useNewUrlParser: true, useUnifiedTopology: true
})
app.set('view engine', 'ejs')
app.use(express.urlencoded({ extended: false}))
// More code here...
app.listen(process.env.PORT || 5000);
Here is the detailed log of the issue I'm facing:
[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
C:\Users\apsoltanian-pc\Documents\js\url-shortener\node_modules\mongoose\lib\connection.js:807
const serverSelectionError = new ServerSelectionError();
^
// More error details here...
Node.js v17.7.2
[nodemon] app crashed - waiting for file changes before starting...
Any help would be greatly appreciated. Thank you!
I'm facing difficulties connecting to my MongoDB database while trying to run my JavaScript, Express, and MongoDB based URL shortener project. Any advice or assistance would be highly appreciated. Thank you!