Export and Require Modules in Nodejs tutorial to learn easy way in javascript
Export and Require Modules in Nodejs tutorial to learn easy way in javascript
# JavaScript node js # Export and Require
This tutorial explains the default method of exporting modules and then importing / requiring them inside your projects.Node.js is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser.Node.js comes with a set of built-in modules that we can use in our code without having to install them. To do this, we need to require the module using the require keyword and assign the result to a variable. This can then be used to invoke any methods the module exposes.Now let’s look at how to create our own module and export it for use elsewhere in our program. Start off by creating a export.js file and adding the following:
module.exports.variable1=32
exports.variable2=35
exports.nodesample= function () {
console.log("we export function")
}
Now create an require.js file in the same folder and add this:
const apnode= require("./export")
console.log("variable1= "+apnode.variable1)
console.log("variable2= "+apnode.variable2)
apnode.nodesample()
Run the program using" node require.js" and you should see the following output to the terminal:
-------------------------
variable1= 32
variable2= 35
we export function
-----------------------------
Видео Export and Require Modules in Nodejs tutorial to learn easy way in javascript канала Rise of Crypto Brothers
# JavaScript node js # Export and Require
This tutorial explains the default method of exporting modules and then importing / requiring them inside your projects.Node.js is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser.Node.js comes with a set of built-in modules that we can use in our code without having to install them. To do this, we need to require the module using the require keyword and assign the result to a variable. This can then be used to invoke any methods the module exposes.Now let’s look at how to create our own module and export it for use elsewhere in our program. Start off by creating a export.js file and adding the following:
module.exports.variable1=32
exports.variable2=35
exports.nodesample= function () {
console.log("we export function")
}
Now create an require.js file in the same folder and add this:
const apnode= require("./export")
console.log("variable1= "+apnode.variable1)
console.log("variable2= "+apnode.variable2)
apnode.nodesample()
Run the program using" node require.js" and you should see the following output to the terminal:
-------------------------
variable1= 32
variable2= 35
we export function
-----------------------------
Видео Export and Require Modules in Nodejs tutorial to learn easy way in javascript канала Rise of Crypto Brothers
Показать
Комментарии отсутствуют
Информация о видео
18 февраля 2021 г. 3:13:59
00:10:16
Другие видео канала
How to use Font Awesome Icons offline and Google fonts in HTML and CSSHow to use Call,Apply and Bind with rest Array ExampleJavascript Tutorial to learn Promises and Async Await easilyJavaScript Programming All-in-One Tutorial Series in 30 minutesHtml and CSS image gallery with Background using Hover, shadow and transition effectHow to create Snake Game in Javascript by using HTML and CSSHow to start stop App using Frontend and Backend with JavascriptHTML and CSS tutorial to create Web Calendar sheet with hover effects in BracketsHow to learn map reduce filter and sort in Javascipt with nodeJS easyJavascript For Loop and While Loop | Javascript Tutorial For BeginnersHTML and CSS part 1: How to Code HTML and CSS in Atom editor.How to create very important Javascript Function tutorial in detail in different ways.Excel VBA Tutorial for Beginners Part 2Innovative Crypto Trading AI Bot Powered by Deep Learning | Boost Your Crypto Investments #btcHow to add Multiple Textboxes in Userform by using Excel VBAHow to create Login page by using Excel VBA Userform with passwordchar.How to create Chart in Userform by using VBA code in ExcelExcel VBA Progress bar on Userform TutorialExcel VBA tutorial to add digital clock by using UserformExcel VBA Tutorial for Beginners Part 1