Hi all,
I’m currently working through the React course and I’m at the point of setting up the Node backend. I ran into the same issues that others have previously mentioned to do with Bcrypt and luckily I have resolved that.
However, I now run into an issue when running node seed.js. I get this following error and don’t know what to do to resolve it.
/workspaces/React/vidly-api-node/node_modules/mongodb-core/lib/topologies/server.js:503
new MongoNetworkError(
^
MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16) {
name: 'MongoNetworkError'
}]
at Pool.<anonymous> (/workspaces/React/vidly-api-node/node_modules/mongodb-core/lib/topologies/server.js:503:11)
at Pool.emit (node:events:526:28)
at Connection.<anonymous> (/workspaces/React/vidly-api-node/node_modules/mongodb-core/lib/connection/pool.js:326:12)
at Object.onceWrapper (node:events:646:26)
at Connection.emit (node:events:526:28)
at Socket.<anonymous> (/workspaces/React/vidly-api-node/node_modules/mongodb-core/lib/connection/connection.js:245:50)
at Object.onceWrapper (node:events:646:26)
at Socket.emit (node:events:526:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
I then update the seed.js file’s seed method to connect to mongoose like so:
await mongoose.connect(config.get("db"), {
useNewUrlParser: true,
useUnifiedTopology: true,
});
Which the just creates a server error, as such:
const serverSelectionError = new ServerSelectionError();
^
MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
at NativeConnection.Connection.openUri (/workspaces/React/vidly-api-node/node_modules/mongoose/lib/connection.js:828:32)
at Mongoose.connect (/workspaces/React/vidly-api-node/node_modules/mongoose/lib/index.js:335:15)
at seed (/workspaces/React/vidly-api-node/seed.js:42:18)
at Object.<anonymous> (/workspaces/React/vidly-api-node/seed.js:64:1)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
reason: TopologyDescription {
type: 'Single',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map(1) {
'localhost:27017' => ServerDescription {
address: 'localhost:27017',
error: Error: connect ECONNREFUSED 127.0.0.1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16) {
name: 'MongoNetworkError'
},
roundTripTime: -1,
lastUpdateTime: 2956358,
lastWriteDate: null,
opTime: null,
type: 'Unknown',
minWireVersion: 0,
maxWireVersion: 0,
hosts: [],
passives: [],
arbiters: [],
tags: []
}
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
}
Any ideas?