balcoder / mern_auctioneer

Full stack MERN (MongoDB, Express.js, React, and Node.js.) auctioneer site with authentication using JWT, Firebase, and Google OAuth, CRUD operations on property listing and image uploads with friendly search features.
0 stars 1 forks source link

No documentation on .env file and Mongodb connection issues #1

Open rootless4real opened 1 month ago

rootless4real commented 1 month ago

The main code is looking for the MONGO_URI from the .env file, but none is included. My attempts to provide the correct syntax in a .env file didn't work.

I tried hard coding the mongdodb connection in the api/index.js file: // mongoose.connect(process.env.MONGO_URI) mongoose.connect("mongodb://localhost:27017/auction")

Which eliminated the start up errors about undefined uri parameter, however, when attempting to create a login via the front end, I get a refused connection from mongodb via Mongoose:

MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 at _handleConnectionErrors (/var/www/html/mern_auctioneer/node_modules/mongoose/lib/connection.js:897:11) at NativeConnection.openUri (/var/www/html/mern_auctioneer/node_modules/mongoose/lib/connection.js:848:11) { reason: TopologyDescription { type: 'Unknown', servers: Map(1) { 'localhost:27017' => [ServerDescription] }, stale: false, compatible: true, heartbeatFrequencyMS: 10000, localThresholdMS: 15, setName: null, maxElectionId: null, maxSetVersion: null, commonWireVersion: 0, logicalSessionTimeoutMinutes: null }, code: undefined }

This is my first time troubleshooting a node.js app. I've learned a lot from your code (thank you for sharing so much). I would like to fix this problem and I'm not sure how to do it. Help please.

balcoder commented 1 month ago

Hi James, Thanks for the feedback. The reason I used an .env file is because you don't want to upload your passwords to database to github for everyone to see. If you want to get the app working for yourself you will have to create your own database in mongo . It has a free tier and the docs are good. https://www.mongodb.com/ . Hope this helps.

On Wed, Jul 31, 2024 at 8:38 PM James @.***> wrote:

The main code is looking for the MONGO_URI from the .env file, but none is included. My attempts to provide the correct syntax in a .env file didn't work.

I tried hard coding the mongdodb connection in the api/index.js file: // mongoose.connect(process.env.MONGO_URI) mongoose.connect("mongodb://localhost:27017/auction")

Which eliminated the start up errors about undefined uri parameter, however, when attempting to create a login via the front end, I get a refused connection from mongodb via Mongoose:

MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 at _handleConnectionErrors (/var/www/html/mern_auctioneer/node_modules/mongoose/lib/connection.js:897:11) at NativeConnection.openUri (/var/www/html/mern_auctioneer/node_modules/mongoose/lib/connection.js:848:11) { reason: TopologyDescription { type: 'Unknown', servers: Map(1) { 'localhost:27017' => [ServerDescription] }, stale: false, compatible: true, heartbeatFrequencyMS: 10000, localThresholdMS: 15, setName: null, maxElectionId: null, maxSetVersion: null, commonWireVersion: 0, logicalSessionTimeoutMinutes: null }, code: undefined }

This is my first time troubleshooting a node.js app. I've learned a lot from your code (thank you for sharing so much). I would like to fix this problem and I'm not sure how to do it. Help please.

— Reply to this email directly, view it on GitHub https://github.com/balcoder/mern_auctioneer/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4X3K32CYBLA2W74XCYQXLZPE4JRAVCNFSM6AAAAABLZEAFGGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGQ2DANZZHA2TANI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

rootless4real commented 1 month ago

Thank you so much replying.

No problem at all not uploading your actual .env file (not expected at all). It would be great to have an example .env file (without any passwords). Often this is accomplished by creating a .env.sample that can be used as a base for creating the local .env file. It would have the needed variables named in it; e.g. MONGO_URI=

I'm running mongo locally, so cost isn't a problem. I don't know how to structure or create a mongo database (really familiar with SQL, not so much with NoSQL). Isn't there some sort of mongo schema that should be included with the project so that it gets created correctly?

Thanks again,

James

On Thu, Aug 1, 2024 at 1:40 AM Des Barrett @.***> wrote:

Hi James, Thanks for the feedback. The reason I used an .env file is because you don't want to upload your passwords to database to github for everyone to see. If you want to get the app working for yourself you will have to create your own database in mongo . It has a free tier and the docs are good. https://www.mongodb.com/ . Hope this helps.

On Wed, Jul 31, 2024 at 8:38 PM James @.***> wrote:

The main code is looking for the MONGO_URI from the .env file, but none is included. My attempts to provide the correct syntax in a .env file didn't work.

I tried hard coding the mongdodb connection in the api/index.js file: // mongoose.connect(process.env.MONGO_URI) mongoose.connect("mongodb://localhost:27017/auction")

Which eliminated the start up errors about undefined uri parameter, however, when attempting to create a login via the front end, I get a refused connection from mongodb via Mongoose:

MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 at _handleConnectionErrors

(/var/www/html/mern_auctioneer/node_modules/mongoose/lib/connection.js:897:11)

at NativeConnection.openUri

(/var/www/html/mern_auctioneer/node_modules/mongoose/lib/connection.js:848:11)

{ reason: TopologyDescription { type: 'Unknown', servers: Map(1) { 'localhost:27017' => [ServerDescription] }, stale: false, compatible: true, heartbeatFrequencyMS: 10000, localThresholdMS: 15, setName: null, maxElectionId: null, maxSetVersion: null, commonWireVersion: 0, logicalSessionTimeoutMinutes: null }, code: undefined }

This is my first time troubleshooting a node.js app. I've learned a lot from your code (thank you for sharing so much). I would like to fix this problem and I'm not sure how to do it. Help please.

— Reply to this email directly, view it on GitHub https://github.com/balcoder/mern_auctioneer/issues/1, or unsubscribe < https://github.com/notifications/unsubscribe-auth/AA4X3K32CYBLA2W74XCYQXLZPE4JRAVCNFSM6AAAAABLZEAFGGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGQ2DANZZHA2TANI>

. You are receiving this because you are subscribed to this thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/balcoder/mern_auctioneer/issues/1#issuecomment-2262382459, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHSKIJ5IRCWJCCN7A5OSZ3ZPHX75AVCNFSM6AAAAABLZEAFGGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENRSGM4DENBVHE . You are receiving this because you authored the thread.Message ID: @.***>

-- James Fowler/方志宇 @. @. Public Key: https://sites.google.com/site/poorpermissions/pk/fowler_publickey?attredirects=0&d=1 http://rootless.googlepages.com/fowler_publickey

rootless4real commented 1 month ago

Any chance for an example .env file? Every time I get one variable discovered and added I run into another missing one. Thanks.