'querySrv ENOTFOUND _mongodb._tcp.cluster0-lmapeno.mongodb.net
i'm trying to run this airbnb clone: https://github.com/ricardovasconcelos/AirbnbClone made with react, node, socket.io and mongodb, when it comes to frontend, it runs perfectly, but I'm having an error when trying to run the backend.
This is my package.json:
{
"name": "backend",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"dev": "nodemon src/server.js",
"start": "nodemon src/server.js"
},
"license": "MIT",
"devDependencies": {
"nodemon": "^1.19.4"
},
"dependencies": {
"colors": "^1.4.0",
"cors": "^2.8.5",
"express": "^4.17.3",
"mongoose": "^5.7.3",
"multer": "^1.4.2",
"socket.io": "^2.4.1",
"socket.io-client": "^4.4.1"
}
}
This is my database.js:
const mongoose = require('mongoose')
mongoose.connect('mongodb+srv://airbnb:[email protected]/airbnbClone?retryWrites=true&w=majority', {
useNewUrlParser:true,
useUnifiedTopology: true
})
This is my server.js:
const express = require('express')
const routes = require('./routes')
const cors = require('cors')
const path = require('path')
const socketio = require('socket.io')
const http = require('http')
require('./database/database')
const server = express()
const app = http.Server(server)
const io = socketio(app)
const connectedUsers = {}
io.on('connection', socket => {
const { user_id } = socket.handshake.query
connectedUsers[user_id] = socket.id
})
server.use((req,res,next) => {
req.io = io
req.connectedUsers = connectedUsers
return next()
})
server.use(cors())
server.use(express.json())
server.use('/files', express.static(path.resolve(__dirname, '..','uploads')))
server.use(routes)
app.listen(3333, ()=>console.log('running on 3333'))
This error appears:
$ nodemon src/server.js
[nodemon] 1.19.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node src/server.js`
(node:59368) Warning: Accessing non-existent property 'count' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:59368) Warning: Accessing non-existent property 'findOne' of module exports inside circular dependency
(node:59368) Warning: Accessing non-existent property 'remove' of module exports inside circular dependency
(node:59368) Warning: Accessing non-existent property 'updateOne' of module exports inside circular dependency
running on 3333
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
Error: querySrv ENOTFOUND _mongodb._tcp.cluster0-lmape.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (node:dns:213:19) {
errno: undefined,
code: 'ENOTFOUND',
syscall: 'querySrv',
hostname: '_mongodb._tcp.cluster0-lmape.mongodb.net'
}
[nodemon] app crashed - waiting for file changes before starting...
I have installed all the dependencies, I would appreciate if someone can help me. Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
