javascript - Nodejs: 'require' a module in Nodejs doesn't work with certain filename -


long-time user, first time asking question.

i have file (let's call file.js) in i'm attempting require file called user.service.js @ top of file:

var userservice = require('./user.service'); 

i'm quite sure path correct , user.service.js file exporting populated object:

in user.service.js:

module.exports = {     signin: signin,     signup: signup,     updateprofile: updateprofile }; 

however, userservice empty object {}. odd thing is, if recreate file name in same directory (e.g. user.service2.js), require statement works properly. or, if rename file.js else, e.g. file2.js, call works. additionally, if require file inside function within user.service.js, statement works well. however, i'd prefer have require statement @ top of file , available functions inside it.

thanks in advance help.

edit:

here's sample code:

var userservice = require('./user.service');  var testfunc = function () {     console.log(userservice);     // logs: {}      var userserviceinternal = require('./user.service');     console.log(userserviceinternal);     // logs:      // {     //     signin: [function],     //     signup: [function],     //     updateprofile: [function]     // } }; 

i figured out...i had circular dependency. comments!


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -