Importing from a Module
Let's start exploring the import side of modules.
A module must import the references it wants to use, such as primitives, functions, objects, or classes exported by other modules. The import
directive should specify the location of the module or file to load. The path may be a relative path, an absolute path, or the name of the module file. In the last case, the location is decided based on the runtime environment and configuration; for example, Node may pick the module from the node_modules
directory. The path in general does not include the file extension. JavaScript offers a variety of import options; choose the one that best meets your needs.
Importing named exports
There are two rules to bring in named exports from another module.
- First, the name specified in the import for the reference should match the exported name.
- Second, the names have to be specified within a
{}
block.
Let’s create a module that imports some references from the temperature
module.
Get hands-on with 1400+ tech skills courses.