How To Create and Use The Module in Node JS | Java Inspires

Published: 24 March 2020
on channel: Java Inspires
35
0

In this video, learn
How To Create and Use The Module in Node JS

#JavaInspires
#NodeJsPractice
https://javainspires.blogspot.com/202...

In this video ...


'How to create and use a module in Node JS
if you have any queries pls comment the same.


Thats it ... THANK YOU


Source Code::


app.js
----------

//this is main js file

var simpleModule = require('./simpleModule');

//lets see what is there in this module

//console.log(simpleModule);//module is empty

//console.log(simpleModule.getCurrentDate());

console.log(simpleModule.info1);//
console.log(simpleModule.getCurrentDate());




simpleModule.js
--------------------------

//In this file we are going to create our module

//lets define a function in this module

function getCurrentDate(){
return new Date().toLocaleString('en-US');
}

//now export this function so that we can access this
//lets declare one variable

var info1 = 'This module contains a function which returns current date';

//export this variable

exports.getCurrentDate = getCurrentDate;
exports.info1 = info1;


Watch video How To Create and Use The Module in Node JS | Java Inspires online without registration, duration hours minute second in high quality. This video was added by user Java Inspires 24 March 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 35 once and liked it 0 people.