Skip to Content
Learn
Intermediate JavaScript Modules
Review

We just learned how to use JavaScript modules. Let’s review what we learned:

Modules in Node.js are reusable pieces of code that can be exported from one program and imported for use in another program.

  • module.exports exports the module for use in another program.
  • require() imports the module for use in the current program.

ES6 introduced a more flexible, easier syntax to export modules:

  • default exports use export default to export JavaScript objects, functions, and primitive data types.
  • named exports use the export keyword to export data in variables.
  • named exports can be aliased with the as keyword.
  • import is a keyword that imports any object, function, or data type.
Folder Icon

Take this course for free

Already have an account?