Beacon24 / v0

4 stars 2 forks source link

Issue starting application #2

Closed lukebelliveau closed 2 years ago

lukebelliveau commented 2 years ago

Issue Cannot start application due to mongoDB error on start

Expected behavior Application starts with command node index.js

Actual behavior Application has a mongoDB connection error when starting application

Steps to reproduce

$ git clone https://github.com/Beacon24/v0.git $ cd v0 $ npm install $ node index.js

See the following error in the console:

BEACON LIT ON PORT 3000
connection error: 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:1142:16) {
  name: 'MongoNetworkError',
  errorLabels: [Array],
  [Symbol(mongoErrorContextSymbol)]: {}
}]
    at Pool.<anonymous> (/Users/lukebelliveau/ROBOT/v0/node_modules/mongodb-core/lib/topologies/server.js:564:11)
    at Pool.emit (node:events:394:28)
    at Connection.<anonymous> (/Users/lukebelliveau/ROBOT/v0/node_modules/mongodb-core/lib/connection/pool.js:317:12)
    at Object.onceWrapper (node:events:514:26)
    at Connection.emit (node:events:394:28)
    at Socket.<anonymous> (/Users/lukebelliveau/ROBOT/v0/node_modules/mongodb-core/lib/connection/connection.js:246:50)
    at Object.onceWrapper (node:events:514:26)
    at Socket.emit (node:events:394: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) {
  errorLabels: [ 'TransientTransactionError' ],
  [Symbol(mongoErrorContextSymbol)]: {}
}

Notes It seems like your index.js script expects a mongoDB server to be running at localhost:27017. Please edit your README.md file with instructions on how to start up your database. Hit me up with any questions.

Beacon24 commented 2 years ago

Aha, yeah, that makes sense. I'll work on this today. I forget, do you have experience with mongo and mongoose?

Beacon24 commented 2 years ago

I'm a little hazy on how all of the following parts fit together, so bear with me. I think you need to have either mongosh or mongod running in the background for index.js to connect to the DB with the following lines (31-34) mongoose.connect('mongodb://localhost:27017/beacon', { useNewUrlParser: true, useCreateIndex: true }); Could that be it? Are you currently running the mongo shell? If not, I believe you can start it up with mongosh and then maybe the app will connect properly? Let me know if I'm on the right track. Thanks for your help!!

lukebelliveau commented 2 years ago

Got it!

You were correct - the MongoDB server was not running. I think in most cases running mongod with MongoDB installed should do it.

I had some maybe Mac-specific issues that were resolved by doing this: https://stackoverflow.com/a/58297378/3124493

I'd suggest an addition to the README - include a link for instructions to install/run MongoDB, indicating that the MongoDB server must be running to run Beacon.

Beacon24 commented 2 years ago

Excellent, thanks! And thanks for the links, I made your suggested changes to the README. Also discovered I can use VSCodes source control tab to easily push/pull changes to GitHub.