Exporting Multiple Functions using module.exports in JS

module.exports is a javascript function created by the module system. It can be used to export function in a Module. Earlier we had discussed the module.exports and exporting a function using module.exports.

In this article we gonna check how to exports multiple function from a module using the module.exports.

date.js

exports.getDate = function(){
    const today = new Date();
    const options = {
        weekday: "long",
        day: "numeric",
        month: "long"
    };

    return today.toLocaleDateString("en-US", options);
}

exports.getDay = function() {
    const today = new Date();
    const options = {
        weekday: "long"
    };

    return today.toLocaleDateString("en-US", options);
}

app.js

const date = require(__dirname + "/date.js");

let dayDetailed= date.getDate();

let day = date.getDay();

console.log(day);

About the Author: smartcoder

You might like

Leave a Reply

Your email address will not be published. Required fields are marked *