I ran into an issue with my Nodejs application.
I have two different apps that are using shared library, which is located so that it is found one level up in node_modules. So i have this structure ./app1/app.js, ./app2/app.js and ./node_modules/shared.libs/index.js.
shared.libs in its turn has some other modules installed, like mongoose, redis etc. Plus some mogoose models with additional functions in them. All are exported from index.js like this:
exports.async = require('async');
exports.config = require('./config');
exports.utils = require('./lib/utils');
And then in apps i import them like this:
var libs = require('shared.libs');
var config = libs.config;
So after this code i can use config which is coming from that shared library.
This part was and is working just fine. But now i need to put additional layer on top of this library (read: provide more unified interface for both apps).
What i tried to do is to add some functions into index.js of shared library and then export the whole object with these functions. But whenever i try to call previously imported (by var libs = require('shared.libs');) object it says that libs is not defined.
What am i doing wrong here?
I generally want to keep other code the same, so i won't need to go over replacing require part everywhere, but at the same time provide additional functionality from shared library which will be available from that imported libs object.
requirethat is not working, etc.exportit and how irequireis pretty much explained. How could i improve it? I have tried directly exporting function likeexports.test = function(){console.log("test");}and thenrequireit from another place, also tried creating new object which implements all needed functions andexportit. Both ways are not working. Whenever i try to call libs.test() it says me that libs is undefined. And whenever i check libs object via node-inspector it gives me same output.exports.sth = require(module), it's all good, but if you also addexports.fun = function() {}, the whole module stops working, is that correct? Doesn't sound quite right.exports.fun = function(){}this only function does not work. But all other things exported in that shared library are still working. I just meant strange behavior that if i check lib itself it is undefined.