This is part two of the Test-driven Development with Nodejs, Express, Mongoose & Jest, in part one, we set up our development environment and r...
For further actions, you may consider blocking this person and/or reporting abuse
Great article!
I will allow myself to make little one suggestion to your article for will make it a diamond.
To enable syntax highlighting in a code section, you needs to open your code block as
```javascript
code
```
Its will look likes
Very helpful. Will try it out
Thank you so much for this input, I will update the article shortly.
Great article and a good example with a modern approach. I learned a lot. So thanks for putting all this together.
Few questions though:
and what about the views-part?
Good news for tech devs!
I built and deployed a CLI to help you architect a Nodejs application using the MVC design pattern & the Layered Architecture. Contributions are welcomed #cli #npm #npmpackage
install using:
npm i -g @eetukudo/node-mvc
npmjs.com/package/@eetukudo/node-mvc
Emmanuel this is a great post!
I would like to get your honest feedback of my MVC framework. I have several years (6) applying the MVC concept on top of the express module. This is the latest version I made with ES6 best practices.
Dev.to Article
dev.to/digitalprimeint/mvc-framewo...
Documentation:
npmjs.com/package/plugdo-mvc
It could be 10 min of your time!
I will install the package and get back.
This is a great example of MVC with Node.
What’s the reasoning behind exporting a class with all static methods instead of just exporting the methods themselves?
It simply developer preference, The first thing that came to mind was the "Don't Repeat Yourself (DRY)" approach. Exporting each method can as well become verbose. Let me know if you can improve the code. Thanks.
I think exporting a class with all its methods is quite bulky if we only need one or two of them. Security concern might also exposed. Anyway, it's a good article 👍 Thank you
Very nice article. I will restructure my current project to follow this "layered" structure. I'm trying to become more aware of separating concerns. Hopefully, I'll reap the benefits early on. Thank for the article 🙂
Thank you so much @tonyscruze . The first benefit is that you can write testable code on the fly.
This is by far the best overview of MVC architecture in express that I have come across. Seriously, like a year of trying to get my head around it and this overview and actually really concise and clever syntax (like use of static class methods) has really helped me figure this out! thank you so much 🤟🤟💕
I've just started exploring the MVC architecture, it seems a little overwhelming linking the different folder/file structures to each other. This is a great article to adding a bit more clarity to my confusion but again I've come across a whole new "services" folder and I've not used it in my CRUD todo application.
What I'm uncertain of is, where to begin when creating an app using the MVC concept.
I tend to get confused about which file is to be linked/imported where. Perhaps if you can give me a few pointers that'd be great or maybe point me to another article or perhaps a resource. Thanks
Emmanuel this is a great post!
But I would like to ask a question.
If we already had try catch block at Controller, then do we need to implement them again in Service layer? There is a similar case study on a youtube channel name "Laravel Daily" (link https://www.youtube.com/watch?v=0hyRw7zeVcs&t=182s) and at 4:07 the video author (Povilas) said "A Service should just throw an exception". So is it not a good practice to catch exception anywhere else beside Controller?
What do you think about it?
Thank you,
Quy
A reference on how to configure Mongo locally or on cloud will be great, this made me stop reading it as tutorial and switch to a "he's just explaining a pattern" mindset. Good enough though, thanks!
Thank you @thxv3n0lvl for the feedback, I will write an article on how to create a MongoDB database on MongoDB-Atlas and managing MongoDB databases with MongoDB compass.
Great tutorial. Thank you for sharing
It it good writting,
when i am reading i thinked ArticleService.js file is the Controler part of MVC.
but it was not. then ArticaleSErvice.js is in which part of MVC?
No, The ArticleService.js is in a separate folder name services, it should be within the root directory of the project. This is because we are using Layered Architecture, there is a need to separate the business logic from the controller.
Thank you for sharing, it is very helpful for me to learn MVC.
Can I translate your article into Chinese and allow it to be posted on the HelloGithub(hellogithub.com/) community platform?
Yes, you can. Let me know how it comes out. Best.
it good writting
Where to place middlewares in this project structure?
article.routes.js should be the place for the middleware like
Nice article.
Why did you call folder as Services where you have written all database related functions?
Ever great article i found in internet for mvc structure in node express. Keep it up bro.
Excellent and very helpful. Thanks
Can you please tell me why you are using asyn wait ? because in my point of view code will be execute as synchrounously...!
Hi,
I have a question, why declare all methods as static, instead of creating a instance of class to access them?
Any specific reason to this?
Thanks,
Ajay Vamsi