Загрузка страницы

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
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
18 февраля 2021 г. 3:13:59
00:10:16
Яндекс.Метрика