Help needed to solve this

Hey there,

I’m a newbie to NodeJS. I’m using visual studio code to write codes. I’ve already learned the basic of first-class functions, functional expressions, modules, object and object literals, etc. I’ve written some code with a little knowledge, I have given it below.

I’ve created the following module:

var name = {
firstname: ‘Essays’,
lastname: ‘Chief’,
welcome: function() {
console.log(‘Welcome,’ + ’ ’ + this.firstname + ’ ’ + this.lastname);
}
};
when I invoke the function directly using name.welcome(); it gives the output “Welcome, Essays Chief”.
when I try to invoke this module from another code as below,
require(’./filename.js); it works.

However, when I try to invoke the function in this module from another code as below,

var wish = require(’./filename);
wish();

and replacing name.welcome(); with module.exports = name.welcome();

I got the output, “Welcome, undefined undefined”.

What’s the actual error with that code? I couldn’t get it.

I’ve tried to use first class function structure and function expression on it. However, I’m getting confused about it. Can you help me to resolve this?

How can I write the given function,
welcome: function() {
console.log(‘Welcome,’ + ’ ’ + this.firstname + ’ ’ + this.lastname);
}
using the first class template or function expression to access it from another program?

and, I’ve failed to get the required result when I use first class function by passing parameters.

Any help will be appreciated. Thanks a lot.

I got the required output when I changed wish(); to wish;

because the error was saying that wish is not a function. I don’t know why the error was alike. the exact way to write the code is,

var wish = require(’./filename’);
wish();

however, I got the output with the following code.

var wish = require(’./filename’);
wish;

I exported the module as follows.

module.exports = name.welcome();

what I learned was, I should write the code as,

module.exports = name.welcome;

but, it doesn’t work to get the required output. What I have wrote was not exactly following the syntax. I don’t know why it didn’t work and how it worked when I changed wish(); to wish;

please help me out to resolve this. thanks a lot.