1

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?

2

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. Can you check my edit and may be explain me?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.