Week 4 Flashcards
(118 cards)
In node.js, how is each module defined?
JS defines each module
what are local modules?
modules that are defined within your project
how do you make variables and functions that are defined in a module/file accessible to other modules?
you have to export them
what is the module.exports property used for?
to export items from the module
what is the single-responsibility principle?
“every module, class or function in a computer program should have responsibility over a single part of that program’s functionality”.
what is the most accurate phrase for defining the single responsibility principle
a function should do one thing and do it well
what does the acronym DRY stand for?
don’t repeat yourself
what does the acronym WET stand for?
write everything twice
are the module.exports property names bananable?
yes, but it makes sense to keep the property names consistent with the item names
what does node initialize the module.exports property to?
an empty object
what is the exports variable initialized to?
the module.exports property value
what are the options for exporting multiple items from a module?
- assigning an object to the module.exports property
- set properties on the module.exports object
- exports shortcut
how do you export a single item from a module?
assign module.exports to the single item
if you export just a single item from a module, can you export more items later?
no
what does it mean for a module to be dependent on another module?
the module requires something from another,
a module’s dependencies are the other modules required for it to run properly
What is the other term for a module’s dependencies?
a requirement
assign an object to the module.exports property with the properties of add and subtract
module.exports = {
add,
subtract
};
set the properties of add and subtract directly on the module.exports object
module.exports.add = add
module.exports.subtract = subtract
use the exports shortcut to add the add function as a property onto the exports object
exports.add = add
what is the format to export a single item from a module; export the multiply function
module.exports = multiply
what does the built-in require function allow us to do?
import items from a module
how does the require function work?
it takes in a relative path from the module in which require is being called (the module that you wish to export into), to the module you wish to import
when importing JS files, what are you able to omit?
the .js in the file path
how are multiple items exported from a module?
as properties of the exported object