i am running express.js inside electron and i am trying to connect mongodb composs to expressjs
when i start my express.js using electron i am getting error in mongodb
i have created the db in mongodb composs here is the error
here is the code for express .js
const express = require("express");
const mongoose = require("mongoose");
const cors = require("cors");
async function startExpressServer() {
// Connect to MongoDB
await mongoose.connect("mongodb://localhost:27017/pos", {
useNewUrlParser: true,
useUnifiedTopology: true,
});
console.log("Connected to MongoDB");
const expressApp = express();
expressApp.use(cors());
expressApp.get("/", (req, res) => {
res.send("Hello World from Express!");
});
return expressApp;
}
module.exports = { startExpressServer };
in main.js i have this code which stats my express app
app.on("ready", async () => {
// Start the Express server
const expressApp = await startExpressServer();
const port = 3001;
expressApp.listen(port, () => {
console.log(`Server listening on port ${port}`);
});
createMainWindow();
});
this code worked and ran the express app before i added monogo db connetion
2
Answers
To get rid of the first warning you can try this before the connect statement.
To suppress the warning make the
mongoose.set('strictQuery', true);
. and instead oflocalhost
and0.0.0.0