javascript - JS, using foo.exports to return an array to share across different pages -


i have 2 js files in node.js app using socket.io , need share array between 2 files, using js exports so:

foo.exports = function(){     return usernames } 

this works great if array has values, if array empty doesn't return empty array returns error in terminal:

typeerror: object #<object> has no method 'rooms' 

in file error occurs include js array so:

var chat = require('./index.js') chat.rooms() 

now, thinking because array empty js doesn't recognize empty function function @ all, tried below code make usernames array have value (if empty, push 'empty' array). check value 'empty' in array:

but still same error...

if(usernames.length > 0){     return usernames;     console.log('usernames has values'); } else {     console.log('empty usernames array');     return usernames.push('empty'); } 

regards


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -