meabhisingh / mernProjectEcommerce

This is MERN Stack Ecommerce Project Made to Teach MERN Stack on YouTube
1.15k stars 828 forks source link

"app-crashed --waiting for file changes before starting..."how to fix it #41

Open amitrao91 opened 1 year ago

amitrao91 commented 1 year ago

every time my code is working fine but after few second it is showing ""

"const serverSelectionError = new ServerSelectionError(); ^

MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 at Connection.openUri (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\connection.js:825:32) at C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\index.js:417:10 at C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\helpers\promiseOrCallback.js:41:5
at new Promise () at promiseOrCallback (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\helpers\promiseOrCallback.js:40:10) at Mongoose._promiseOrCallback (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\index.js:1270:10) at Mongoose.connect (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\index.js:416:20) at connectDatabase (C:\Users\Amit Rao\Desktop\MERN PROJECT\backend\config\database.js:5:6) at Object. (C:\Users\Amit Rao\Desktop\MERN PROJECT\backend\server.js:10:1) at Module._compile (node:internal/modules/cjs/loader:1218:14) { reason: TopologyDescription { type: 'Unknown', servers: Map(1) { 'localhost:27017' => ServerDescription { address: 'localhost:27017', type: 'Unknown', hosts: [], passives: [], arbiters: [], tags: {}, minWireVersion: 0, maxWireVersion: 0, roundTripTime: -1, lastUpdateTime: 6053295, lastWriteDate: 0, error: MongoNetworkError: connect ECONNREFUSED ::1:27017 at connectionFailureError (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongodb\lib\cmap\connect.js:387:20) at Socket. (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongodb\lib\cmap\connect.js:310:22) at Object.onceWrapper (node:events:628:26) at Socket.emit (node:events:513:28) at emitErrorNT (node:internal/streams/destroy:151:8) at emitErrorCloseNT (node:internal/streams/destroy:116:3) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { cause: Error: connect ECONNREFUSED ::1:27017 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1283:16) { errno: -4078, code: 'ECONNREFUSED', syscall: 'connect', address: '::1', port: 27017 }, [Symbol(errorLabels)]: Set(1) { 'ResetPool' } }, topologyVersion: null, setName: null, setVersion: null, electionId: null, logicalSessionTimeoutMinutes: null, primary: null, me: null, '$clusterTime': null } }, stale: false, compatible: true, heartbeatFrequencyMS: 10000, localThresholdMS: 15, setName: null, maxElectionId: null, maxSetVersion: null, commonWireVersion: 0, logicalSessionTimeoutMinutes: null }, code: undefined } Node.js v19.2.0 [nodemon] app crashed - waiting for file changes before starting..."

rajgorhetal commented 1 year ago

check if you have a valid mongodb connection string in your config.env file (Backend> Config> config.env) For eg: (Your config.env should have valid values for all the below variables (assuming you have local version of Mongodb)

PORT= NODE_ENV= DB_URI=mongodb://localhost:27017/ STRIPE_API_KEY= STRIPE_SECRET_KEY= JWT_SECRET= JWT_EXPIRE= COOKIE_EXPIRE= SMPT_SERVICE= SMPT_MAIL= SMPT_PASSWORD= SMPT_HOST= SMPT_PORT= CLOUDINARY_NAME= CLOUDINARY_API_KEY= CLOUDINARY_API_SECRET=

rajgorhetal commented 1 year ago

every time my code is working fine but after few second it is showing ""

"const serverSelectionError = new ServerSelectionError(); ^

MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 at Connection.openUri (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\connection.js:825:32) at C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\index.js:417:10 at C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\helpers\promiseOrCallback.js:41:5 at new Promise () at promiseOrCallback (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\helpers\promiseOrCallback.js:40:10) at Mongoose._promiseOrCallback (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\index.js:1270:10) at Mongoose.connect (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\index.js:416:20) at connectDatabase (C:\Users\Amit Rao\Desktop\MERN PROJECT\backend\config\database.js:5:6) at Object. (C:\Users\Amit Rao\Desktop\MERN PROJECT\backend\server.js:10:1) at Module._compile (node:internal/modules/cjs/loader:1218:14) { reason: TopologyDescription { type: 'Unknown', servers: Map(1) { 'localhost:27017' => ServerDescription { address: 'localhost:27017', type: 'Unknown', hosts: [], passives: [], arbiters: [], tags: {}, minWireVersion: 0, maxWireVersion: 0, roundTripTime: -1, lastUpdateTime: 6053295, lastWriteDate: 0, error: MongoNetworkError: connect ECONNREFUSED ::1:27017 at connectionFailureError (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongodb\lib\cmap\connect.js:387:20) at Socket. (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongodb\lib\cmap\connect.js:310:22) at Object.onceWrapper (node:events:628:26) at Socket.emit (node:events:513:28) at emitErrorNT (node:internal/streams/destroy:151:8) at emitErrorCloseNT (node:internal/streams/destroy:116:3) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { cause: Error: connect ECONNREFUSED ::1:27017 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1283:16) { errno: -4078, code: 'ECONNREFUSED', syscall: 'connect', address: '::1', port: 27017 }, [Symbol(errorLabels)]: Set(1) { 'ResetPool' } }, topologyVersion: null, setName: null, setVersion: null, electionId: null, logicalSessionTimeoutMinutes: null, primary: null, me: null, '$clusterTime': null } }, stale: false, compatible: true, heartbeatFrequencyMS: 10000, localThresholdMS: 15, setName: null, maxElectionId: null, maxSetVersion: null, commonWireVersion: 0, logicalSessionTimeoutMinutes: null }, code: undefined } Node.js v19.2.0 [nodemon] app crashed - waiting for file changes before starting..."

Check above comment, it will help. Thanks