Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (120 points)

Server connected on port 3000

MongooseError [MongooseServerSelectionError]: connect ECONNREFUSED 127.0.0.1:27071

    at new MongooseServerSelectionError (C:\Test Project\backend\node_modules\mongoose\lib\error\serverSelection.js:24:11)

    at NativeConnection.Connection.openUri (C:\Test Project\backend\node_modules\mongoose\lib\connection.js:823:32)

    at Mongoose.connect (C:\Test Project\backend\node_modules\mongoose\lib\index.js:333:15)

    at Object.<anonymous> (C:\Test Project\backend\database\mongoose.js:5:10)

    at Module._compile (internal/modules/cjs/loader.js:1156:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)

    at Module.load (internal/modules/cjs/loader.js:1000:32)

    at Function.Module._load (internal/modules/cjs/loader.js:899:14)

    at Module.require (internal/modules/cjs/loader.js:1042:19)

    at require (internal/modules/cjs/helpers.js:77:18)

    at Object.<anonymous> (C:\Test Project\backend\app.js:4:19)

    at Module._compile (internal/modules/cjs/loader.js:1156:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)

    at Module.load (internal/modules/cjs/loader.js:1000:32)

    at Function.Module._load (internal/modules/cjs/loader.js:899:14)

    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {

  message: 'connect ECONNREFUSED 127.0.0.1:27071',

  name: 'MongooseServerSelectionError',

  reason: TopologyDescription {

    type: 'Single',

    setName: null,

    maxSetVersion: null,

    maxElectionId: null,

    stale: false,

    compatible: true,

    compatibilityError: null,

    logicalSessionTimeoutMinutes: null,

    heartbeatFrequencyMS: 10000,

    localThresholdMS: 15,

    commonWireVersion: null

  },

  [Symbol(mongoErrorContextSymbol)]: {}

}

PS C:\Test Project\backend> node app.js

C:\Test Project\backend\database\mongoose.js:1

import mongoose, { promise, connect } from 'mongoose';

^^^^^^

    at wrapSafe (internal/modules/cjs/loader.js:1070:16)

    at Module._compile (internal/modules/cjs/loader.js:1120:27)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)

    at Module.load (internal/modules/cjs/loader.js:1000:32)

    at Function.Module._load (internal/modules/cjs/loader.js:899:14)

    at Module.require (internal/modules/cjs/loader.js:1042:19)

    at require (internal/modules/cjs/helpers.js:77:18)

    at Object.<anonymous> (C:\Test Project\backend\app.js:4:19)

    at Module._compile (internal/modules/cjs/loader.js:1156:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)

PS C:\Test Project\backend> node app.js

C:\Test Project\backend\database\mongoose.js:1

import mongoose, { promise, connect } from 'mongoose';

^^^^^^

    at wrapSafe (internal/modules/cjs/loader.js:1070:16)

    at Module._compile (internal/modules/cjs/loader.js:1120:27)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)

    at Module.load (internal/modules/cjs/loader.js:1000:32)

    at Function.Module._load (internal/modules/cjs/loader.js:899:14)

    at Module.require (internal/modules/cjs/loader.js:1042:19)

    at require (internal/modules/cjs/helpers.js:77:18)

    at Object.<anonymous> (C:\Test Project\backend\app.js:4:19)

    at Module._compile (internal/modules/cjs/loader.js:1156:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)

PS C:\Test Project\backend> node app.js

Server connected on port 3000

MongooseError [MongooseServerSelectionError]: connect ECONNREFUSED 127.0.0.1:27071

    at new MongooseServerSelectionError (C:\Test Project\backend\node_modules\mongoose\lib\error\serverSelection.js:24:11)

    at NativeConnection.Connection.openUri (C:\Test Project\backend\node_modules\mongoose\lib\connection.js:823:32)

    at Mongoose.connect (C:\Test Project\backend\node_modules\mongoose\lib\index.js:333:15)

    at Object.<anonymous> (C:\Test Project\backend\database\mongoose.js:5:10)

    at Module._compile (internal/modules/cjs/loader.js:1156:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)

    at Module.load (internal/modules/cjs/loader.js:1000:32)

    at Function.Module._load (internal/modules/cjs/loader.js:899:14)

    at Module.require (internal/modules/cjs/loader.js:1042:19)

    at require (internal/modules/cjs/helpers.js:77:18)

    at Object.<anonymous> (C:\Test Project\backend\app.js:4:19)

    at Module._compile (internal/modules/cjs/loader.js:1156:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)

    at Module.load (internal/modules/cjs/loader.js:1000:32)

    at Function.Module._load (internal/modules/cjs/loader.js:899:14)

    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {

  message: 'connect ECONNREFUSED 127.0.0.1:27071',

  name: 'MongooseServerSelectionError',

  reason: TopologyDescription {

    type: 'Single',

    setName: null,

    maxSetVersion: null,

    maxElectionId: null,

    servers: Map { '127.0.0.1:27071' => [ServerDescription] },

    stale: false,

    compatible: true,

    compatibilityError: null,

    logicalSessionTimeoutMinutes: null,

    heartbeatFrequencyMS: 10000,

    localThresholdMS: 15,

    commonWireVersion: null

  },

  [Symbol(mongoErrorContextSymbol)]: {}

}

Code in app.js

const express = require('express');
const app = express();
const mongoose = require('./database/mongoose');
app.listen(3000, () => console.log("Server connected on port 3000"));
code in mongoose.js
const mongoose = require('mongoose');
mongoose.promise = global.Promise;
mongoose.connect('mongodb://127.0.0.1:27071/taskmanager' , { useNewUrlParser: true, useUnifiedTopology: true })
    .then(() => console.log("Database connected"))
    .catch((error) => console.log(error));
module.exports = mongoose;
Please log in to answer this question.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...