Reputation: 3783
I try to use function from another Javascript file in my Gulpfile, but cannot make it work so far.
The file I need to access in Gulpfile:
var hello = function(){
console.log('Hello')
}
And the way I require it in my Gulpfile:
var tools = require('./public/js/tools.js');
gulp.task('create_subscriptions', function(){
tools.hello();
});
tools.hello() is not a function
is triggered.
What do I do wrong here?
Edit
I did
module.exports = {
hello: hello()
};
Whats the difference wit exports.hello = hello
?
Upvotes: 1
Views: 264
Reputation: 943556
You didn't export anything from your module. Local variables are not exposed, you need to explicitly mark them as public.
exports.hello = hello;
hello: hello()
You have ()
after the variable holding the function. You are calling it and assigning the return value (which is not a function) to your hello property.
Upvotes: 3