Thank you Jesse! I've kept the validator function in a separate file because it uses a module called 'dns' from node which I had to import. So, I did not want the entity to directly depend upon any framework/library. Just separation of concerns.
Is the way you've got it here a common node pattern?
---> Actually the framework I've used is Express.js(Nodejs framework) and it doesn't follow any pattern/architecture. It's completely flexible. This is the first time I'm following any architecture and still exploring, so I might be wrong on some parts😅.
Sorry for a really late reply :(
Jesse Bellingham
Consultant Developer @ Thoughtworks
Really nice article Vighnesh 🙌 super comprehensive. I have a question, and it may just be my lack of experience building with Node, but why do you use a builder function for the entity and have the validation be a separate function passed in? In .NET for example, the entity would be represented with a class (and optionally, interfaces), and if you were aiming for rich domain objects rather than anemic ones, you might have the validation be a part of the class's constructor.
Is the way you've got it here a common node pattern?