简体   繁体   中英

Node.js throwing TypeError: Cannot read property 'testModule' of undefined

So I looked around, looking for solutions for this problem else where and including here, but I keep getting the error

"Cannot read property 'testModule' of undefined."

main.js:

var testing = require('./lib/test.js');
console.log(testing.testModule('user'));

./lib/test.js

module.exports = {
    testModule: function(test){
        return 'Hello '+test+' from module!';
    }
};

What am I doing wrong and what can I do to fix this issue?

Fixed the error. In my original code (not here) I assigned the variable testing as test and called a variable that was non-existent.

Thanks for the tips on the directory structures, though. I appreciate it.

I suck :(

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM