How to create your own module and import them in your index.js file in node Js?

Here, we will write a program to create our own module and import it into our js file. In your directory make a myModule.js file and create myDateTime() function.

Mymodule.js file

var myDateTime = function () {
    return Date();

In your index.js file export the above module using require. And then run the file in the terminal.

index.js file

var myDateTime=require('./myModule');