'Creating single instance or multiple instance of service layer in nodejs
I want to know what should I use to expose my service layer for nodejs api What are the pros and cons of using the approach 1 and 2.
app.post("/", (req, res) => {
// approach 1
const test = testService.play();
// approach 2
const testService = new TestService();
testService.play();
});
------ testService.js --------
class TestService {
play() {}
}
// approach 1
module.exports = new TestService();
// approach 2
module.exports = TestService;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|