Let's say I have 3 node.js projects(1 app backend, 1 app-admin backend, 1 analysis api). In each projects, I have a model schema call loan.
{
attributes: {
userId: { type: String, required: true, index: true, ref: 'users', comment: '用户id' },
amount: { type: Number, required: true, min: 0},
totalAmount: { type: Number, required: true, min: 0},
penaltyInterest: { type: Number, min: 0, required: true, default:
0 }
}
methods: {
getFee () {//some calculation ops
}
save() {//some db ops
}
sendTo3rdComponent() {//some network ops
}
}
This model has: some methods, it's schema design, api implement. How can I reuse it in other two projects.
It's very import to reuse the design and api for multiple projects.
Usually we reuse the component via public it as npm package. However this component has it's own db ops, and network ops. Is it possible and proper to make it as a npm package?
Another option is like eggjs
So what's the elegant solution beside copy-paste?