简体   繁体   中英

nodemon app crashed - waiting for file changes before starting. Can someone sort this out please

import express from 'express';

import bodyParser from 'body-parser';

import mongoose from 'mongoose';

import cors from 'cors';

const app = express();

app.use(bodyParser.json({limit: "30mb", extended: true}));

app.use(bodyParser.urlencoded({limit: "30mb", extended: true }));

app.use(cors());

const CONNECTION_URL = 'mongodb+srv://humoudmajid:humoudmajid123@cluster0.srly03x.mongodb.net/?retryWrites=true&w=majority'

const PORT = process.env.PORT || 5000;

mongoose.connect(CONNECTION_URL, { useNewUrlParser: true, useUnifiedTopology: true })

.then(() => app.listen(PORT, () => console.loq(`Server running on port: ${PORT}`)))

.catch((error) => console.log(error.message));

mongoose.set('useFindAndModify', false);

Im getting this error code.

/Users/humoudmajid/Desktop/Projects/libs/memories_project/server/node_modules/mongoose/lib/index.js:224 throw new Error( \ ${key}` is an invalid option.`); ^

Error: useFindAndModify is an invalid option. at Mongoose.set (/Users/humoudmajid/Desktop/Projects/libs/memories_project/server/node_modules/mongoose/lib/index.js:224:11) at file:///Users/humoudmajid/Desktop/Projects/libs/memories_project/server/index.js:20:10 at ModuleJob.run (node:internal/modules/esm/module_job:198:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:385:24) at async loadESM (node:internal/process/esm_loader:88:5) at async handleMainPromise (node:internal/modules/run_main:61:12) [nodemon] app crashed - waiting for file changes before starting...

It's deprecated now. You don't need mongoose.set('useFindAndModify', false); . Just use mongoose.connect(CONNECTION_URL).then(()=>{console.log('...')})

Delete the line

mongoose.set('useFindAndModify', false);

useFindAndModify is deprecated and not necessary anymore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM