0
我无法导入expressJs中其他模块中的app.js。它的导入,但我无法使用app.js文件无法在expressJs中的其他模块中导入app.js
代码,我定义的函数是这个 - 我有这个 里面/socketroutes/socketroutes.js文件app.js
var app = express();
var expressWs = require('express-ws')(app);
.
.
.
wss= expressWs.getWss();
// console.log(wss); // works fine
app.getWss=function(){
return "hello";
};
app.listen(3001);
module.exports = app;
var app = require('../app');
console.log(app); // prints an empty object {}
console.log(app.getWss()) // returns undefined function and doesn't work
我想在另一个模块中使用app.js中定义的一些变量或函数。因为websocket服务器的实例只能创建一次。我无法在每个模块中创建wss实例。
您是否收到任何错误? – abdulbarik