0
I have the following connection code with Mongodb, it was working perfect, but now gives an error.
const express = require('express');
const mongoose = require('mongoose');
const path = require('path');
const cors = require('cors');
const app = express();
app.use(cors());
const server = require('http').Server(app);
const io = require('socket.io')(server);
io.on("connection", socket => {
socket.on("connectRoom", box => {
socket.join(box);
});
});
mongoose.connect('mongodb+srv://omnistack:[email protected]/omnistack?retryWrites=true', {
useNewUrlParser: true
});
app.use((req, res, next) => {
req.io = io;
return next();
});
app.use(express.json());
app.use(express.urlencoded({ extended: true}));
app.use("/files", express.static(path.resolve(__dirname, "..", "tmp")));
app.use(require("./routes"));
server.listen(process.env.PORT || 3333);
Before I gave a 'Yarn dev' and it connected, now appears the following message on the vscode console :
(node:4532) UnhandledPromiseRejectionWarning: MongoNetworkError: connection 4 to cluster0-shard-00-02-jaf8f.mongodb.net:27017 closed
at TLSSocket.<anonymous> (C:\Users\note-gambali\Desktop\Alexandre\OmniStack\backend\node_modules\mongodb-core\lib\connection\connection.js:352:9)
at Object.onceWrapper (events.js:281:20)
at TLSSocket.emit (events.js:193:13)
at _handle.close (net.js:614:12)
at TCP.done (_tls_wrap.js:412:7)
(node:4532) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4532) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.