š Iām an aspiring full-stack developer from Lagos, Nigeria, fueled by a passion for AI/ML and cloud computing! š I believe in the power of technology to transform lives and make a difference
I had the same doubt earlier, what i think is that it is better to put Mongodb atlas code in server.js bcz in real world scenario, http server needs to connect to db first and then start which would be more convenient if u put it in server.js rather than app.js. Also put MongoDB Connection as separate module/file.
Following is my folder structure :
Backend
App (Follows MVC)
index.js (Contains express app code & calls to MVC part)
Controller
Middlewares
Models
Routes
Database (MongoDB Atlas/mongoose Connection)
db.config.js
Env (Environment variable prod/dev - For mongodb url, etc.)
.env
server.js (Main entry point - code related to http server, mongodb conn etc. here)
Thank you, I've been wondering about this. Where would you put the code that connects to MongoDB Atlas? In
apporserver?it should be a seprate module in a special folder called models
I had the same doubt earlier, what i think is that it is better to put Mongodb atlas code in server.js bcz in real world scenario, http server needs to connect to db first and then start which would be more convenient if u put it in server.js rather than app.js. Also put MongoDB Connection as separate module/file.
Following is my folder structure :
Backend
Thank you, that makes sense! Especially the point about starting the server after the connection was successful.