node.js - node export module unknown console log "undefined" -
so i'm learning export modules node.js
in test.js have (test.js module writen)
var library={ name:"timmy", greet:function(name){ console.log("hello "+ name); } } module.exports.library=library;
in server.js have:
var test=require('./test.js'); console.log(test.library.greet())
then when run node server.js in terminal, gives this:
hello timmy library. undefined
what "undefined" mean? error?
i found similar question here, complicated example couldn't understand.. node module export returning undefined
so here whats happening: console inside server.js
file prints return of function call. since function call (test.library.greet()
) doesn't return explicitly return undefined
implicitly.
thats whats getting printed.
Comments
Post a Comment