?
If you start-to-use a-DB like MONGO, you might is better off creating objects with mongoose and that ' s personal preference as well. As for your example-
1) Export person
Module.exports = person;
2) Import person from another file
Const person = require ('.. /path/to/person ');
3) Create person with the? New ? keyword to call the constructor (very important)
cons T Mitch = newperson ( ' Mitch '
You Should read up on? javascript ' s prototype object.prototype object.create (obj) ?to Create objects and assign the new object ' s prototype as the reference being passed in to? object.create (obj)
Here's an example from MDN
Shape-superclass
functionShape() {
This. x = 0;
This. y = 0;
}
?
Superclass method
Shape. Prototype.move = function(x, y) {
This. x + = x;
This. Y + = y;
Console.info (' Shape moved. ') );
};
?
Rectangle-subclass
functionRectangle() {
Shape. Call (this); //Call Super constructor.
}
?
Subclass extends Superclass
Rectangle. prototype = Object. Create (Shape. prototype);
Rectangle. prototype. Constructor = Rectangle;
?
var rect = newRectangle();
?
Console.log (' is rect of instance of Rectangle? ' ,
Rect instanceofRectangle); //True
Console.log (' is rect of instance of Shape? ' ,
Rect instanceofShape); //True
Rect.move (1, 1); //Outputs, ' Shape moved. '
?
From:https://stackoverflow.com/questions/47006288/node-js-best-way-to-define-entity-class
Node js:best to define entity class