How to fix TypeError: Cannot read property 'foo' of undefined in Node.js | DevErrors