I got an error when I run the code.Is there any errors in my code? This is the code that I enterd.
const express = require("express");
const mongoose= require("mongoose");
const bodyParser = require("body-parser");
const cors = require("cors");
const dotenv=require("dotenv");
const app = express();
require("dotenv").config();
const PORT =process.env.PORT || 8070;
app.use(cors());
app.use(bodyParser.json());
const URL = process.env.MONGODB_URL;
mongoose.connect(URL, {
useCreateIndex: true,
useNewUrlParser:true,
useUnifieldTopologyL:true,
useFindAndModify:false,
});
const connection = mongoose.connection;
connection.once("open", () => {
console.log("Mongodb Connection success!");
})
app.listen(PORT, () => {
console.log('Server is up and running on port number: ${PORT}')
})
i got this error when I give npm start command
backend@1.0.0 start C:\Users\Admin\Desktop\cosmetic\backend node server.js
Server is up and running on port number: ${PORT} (node:4808) UnhandledPromiseRejectionWarning: MongoParseError: options usecreateindex, useunifieldtopologyl, usefindandmodify are not supported at Object.parseOptions (C:\Users\Admin\Desktop\cosmetic\backend\node_modules\mongodb\lib\connection_string.js:281:15) at new MongoClient (C:\Users\Admin\Desktop\cosmetic\backend\node_modules\mongodb\lib\mongo_client.js:62:46) at C:\Users\Admin\Desktop\cosmetic\backend\node_modules\mongoose\lib\connection.js:781:16 at new Promise () at NativeConnection.Connection.openUri (C:\Users\Admin\Desktop\cosmetic\backend\node_modules\mongoose\lib\connection.js:778:19) at C:\Users\Admin\Desktop\cosmetic\backend\node_modules\mongoose\lib\index.js:330:10 at C:\Users\Admin\Desktop\cosmetic\backend\node_modules\mongoose\lib\helpers\promiseOrCallback.js:32:5 at new Promise () at promiseOrCallback (C:\Users\Admin\Desktop\cosmetic\backend\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:10) at Mongoose._promiseOrCallback (C:\Users\Admin\Desktop\cosmetic\backend\node_modules\mongoose\lib\index.js:1151:10) (Use
node --trace-warnings ...to show where the warning was created) (node:4808) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag--unhandled-rejections=strict(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:4808) [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.
The error is pretty straight forward, from Mongoose 6.0 docs:
useNewUrlParser, useUnifiedTopology, useFindAndModify, and useCreateIndex are no longer supported options. Mongoose 6 always behaves as if useNewUrlParser, useUnifiedTopology, and useCreateIndex are true, and useFindAndModify is false. Please remove these options from your code.
These options are no longer supported and you should remove them from the options you're passing to the mongoose connect function.