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

Опубликовано: 24 Март 2020
на канале: 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;


Смотрите видео How To Create and Use The Module in Node JS | Java Inspires онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Java Inspires 24 Март 2020, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 35 раз и оно понравилось 0 людям.