Different ways to export a function

var sayHelloInEnglish = function() {
    return "Hello";
};

var sayHelloInSpanish = funciton() {
    return "Hola";
};

var sayHelloInSwedish = function() {
    return "Hej";
};

//Two functions that gets exported; the third function is not available outside this file.

module.exports.sayHelloInEnglish = sayHelloInEnglish;
module.exports.sayHelloInSpanish = sayHelloInSpanish;

Alternative method 2

module.exports.sayHelloInEnglish = function() {
    return "Hello";
};

module.exports.sayHelloInSpanish = funciton() {
    return "Hola";
};

var sayHelloInSwedish = function() {
    return "Hej";
};

Alternative method 3


module.exports = {
    sayHelloInEnglish = function() {
        return "Hello";
    };
    sayHelloInSpanish = funciton() {
        return "Hola";
    };
};
var sayHelloInSwedish = function() {
    return "Hej";
};

Add your comment