Search code examples
javascriptnode.jsexpressinternationalizationnode-modules

How to create instances of i18n module


I'm trying to create two instances of i18n module, but it doesn't work. Do you know how can make it?

var i18n = require('i18n')
var i18nInstance1 = new i18n()
var i18nInstance2 = new i18n()

Error:

var i18nInstance = new i18n();
                   ^

TypeError: i18n is not a constructor

Thank you so much. Regards,


Solution

  • If it can help peoples, I've resolved my problem by using i18n-factory module.

    For your information, when you require a module not create a singleton of it. If you want to has multiple instance, you have to privatify your logic or using a factory pattern.