#node
What is a Module
A module encapsulates related code into a single unit of code. When creating a module, this can be interpreted as moving all related functions into a file. Let’s illustrate this point with an example involving an application built with Node.js. Imagine that we created a file called greetings.js
and it contains the following two functions:
// greetings.js
sayHelloInEnglish = function() {
return "Hello";
};
sayHelloInSpanish = function() {
If you want to change selection, open document below and click on "Move attachment"
Understanding module.exports and exports in Node.jsou can use modules inside of the browser, read: Understanding JavaScript Modules: Bundling & Transpiling . You can also get a greater understanding of Node in: Your First Week With Node.js. <span>What is a Module A module encapsulates related code into a single unit of code. When creating a module, this can be interpreted as moving all related functions into a file. Let’s illustrate this point with an example involving an application built with Node.js. Imagine that we created a file called greetings.js and it contains the following two functions: // greetings.js sayHelloInEnglish = function() { return "Hello"; }; sayHelloInSpanish = function() { return "Hola"; }; Exporting a Module The utility of greetings.js increases when its encapsulated code can be utilized in other files. So let’s refactor greetings.js to achieve this goal Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details