<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nick Baughan</title>
    <description>The latest articles on DEV Community by Nick Baughan (@nick_baughan_f9ec9942a306).</description>
    <link>https://dev.to/nick_baughan_f9ec9942a306</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1495346%2F08c87fff-b144-45d9-a811-b6b5a9804197.jpeg</url>
      <title>DEV Community: Nick Baughan</title>
      <link>https://dev.to/nick_baughan_f9ec9942a306</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nick_baughan_f9ec9942a306"/>
    <language>en</language>
    <item>
      <title>Understanding Module Specifier</title>
      <dc:creator>Nick Baughan</dc:creator>
      <pubDate>Wed, 19 Mar 2025 18:28:25 +0000</pubDate>
      <link>https://dev.to/nick_baughan_f9ec9942a306/understanding-module-specifier-1ic8</link>
      <guid>https://dev.to/nick_baughan_f9ec9942a306/understanding-module-specifier-1ic8</guid>
      <description>&lt;p&gt;In my previous post, to keep things simple all code files are living together in the same directory. When importing, specifying "./" and then the name of the file tells the compiler or bundler to look in the current directory to find the file. This simple setup works fine for a simple demonstrative example, but in a real project with even a little bit of complexity we need to organize our files better.&lt;/p&gt;

&lt;p&gt;The specifier part of an import statement is how you indicate where the file is located.  As I already mentioned, using "./" indicates "look in the current directory". But the files you need in many cases are probably within a subdirectory. In the example below all of the math functionality has been cleaned up and moved into its own folder. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiapfoo1msv6oy7s0i59g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiapfoo1msv6oy7s0i59g.png" alt="import from a subdirectory" width="800" height="423"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, from the index.js file, to access the add.js file, you would need to use the module specifier "./calculator/add.js". This is saying "look in the current directory for a folder named 'calculator', then inside of it, grab the file named 'add.js'"&lt;/p&gt;

&lt;p&gt;A feature of the module specifiers spec is that if a file isn't explicitly declared in the import statement, the compiler will look for a file named "index.js". This can be used to organize functionality and to clean up the amount of import statements for the consuming code. As you can see below, all of the operation and constants are imported to an index file, where they can be imported with only one import statement.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkzvsxnanldhfeg90ykfw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkzvsxnanldhfeg90ykfw.png" alt="Using an Index file" width="800" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The calculator could be refactored and organized itself. With constants and operations moved to their own nested directory we would need to update our module specifier to take into account the new folder structure. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7agsxr4de3ulo5081yq1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7agsxr4de3ulo5081yq1.png" alt="Image description" width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All of these examples have started with "./" since the subdirectories are in the same folder as the consuming code, but that might not always be the case. Let say that some code wants to import code from a sibling level directory. While “./” can be used to access the current directory, “../” will access one directory higher.&lt;/p&gt;

&lt;p&gt;In the example below, the circle that lives in the operations folder is able to import a file from the constant folder by using "../" to navigate outside of its current directory. That will take it to the &lt;strong&gt;calculator&lt;/strong&gt; directory, where it can access the &lt;strong&gt;constants&lt;/strong&gt; directory. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9i3txuhq5bjjdy8qvr87.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9i3txuhq5bjjdy8qvr87.png" alt="Image description" width="800" height="448"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;This can be done recursively as needed. The deeper the consuming code is relative to the needed code, the more "../" are used. You can combine these like "../../", which would take you two directories higher.&lt;/p&gt;

&lt;p&gt;A good way to think about it is that "./" puts you in the directory of the current file. "../" takes you one directory higher. These patterns can be combined to access and expose code as needed.&lt;/p&gt;

&lt;p&gt;In the next post I'll cover a few more module specifier patterns.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>es6</category>
      <category>modules</category>
      <category>node</category>
    </item>
    <item>
      <title>JavaScript Modules: An Introduction</title>
      <dc:creator>Nick Baughan</dc:creator>
      <pubDate>Wed, 19 Mar 2025 17:36:41 +0000</pubDate>
      <link>https://dev.to/nick_baughan_f9ec9942a306/javascript-modules-an-introduction-4e44</link>
      <guid>https://dev.to/nick_baughan_f9ec9942a306/javascript-modules-an-introduction-4e44</guid>
      <description>&lt;p&gt;When I began as a web developer, &lt;a href="https://property.jamescitycountyva.gov/JamesCity/" rel="noopener noreferrer"&gt;one of the first projects&lt;/a&gt; I worked on had multiple JavaScript files all loaded into the browser using script tags. This was a fragile method for managing multiple files. With one file having a dependency on another, the ordering of these script tags were critical. One script tag out of order would crash the application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="nx"&gt;DOCTYPE&lt;/span&gt; &lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt; &lt;span class="nx"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;en&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;head&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;viewport&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;width=device-width, initial-scale=1.0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Script&lt;/span&gt; &lt;span class="nx"&gt;Tag&lt;/span&gt; &lt;span class="nx"&gt;Example&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/title&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/head&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://code.jquery.com/jquery-3.7.1.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./scripts/main.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/body&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/html&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, since jquery.js is a dependency of main.js, failure to load JQuery will throw an error! Or if the ordering of the script tags were reversed, main.js would try and use JQuery before it had been loaded into the browser. In a simple example like this it doesn't seem too difficult to manage, but with a large production application with multiple developers, it was a nightmare. When trying to refactor and clean up old script tags, a mistake could crash the app.&lt;/p&gt;

&lt;p&gt;Another problem was that everything was loaded onto the global scope. It wasn't very hard to overwrite a variable by accident. Declaring a new variable with the same name of an already existing variable and the first variable was replaced(This was before ES6 introduced "&lt;em&gt;const&lt;/em&gt;"). This would lead to bugs and unexpected behavior.&lt;/p&gt;

&lt;p&gt;JavaScript started as a simple scripting language for the browser, mostly used for form validation and adding a bit of interactivity to otherwise static html pages.&lt;br&gt;
In time developers began using the language to build larger and more dynamic applications. The codebase being used for web applications was growing. Splitting code between files and using third party libraries was a headache. The JavaScript ecosystem needed a module system. &lt;/p&gt;

&lt;p&gt;The JavaScript community began to experiment and design their own module systems. CommonJS and Asynchronous Module Definition were two early specifications. For a time I was most familiar with Asynchronous Module Definition, or AMD for short. Working with ESRI's JavaScript API, which was built on the Dojo Toolkit gave me plenty of experience with the AMD pattern. &lt;/p&gt;

&lt;p&gt;But in 2015 the JavaScript specifications finally included a built in module system. &lt;em&gt;JavaScript Modules&lt;/em&gt; or &lt;em&gt;ES6 Modules&lt;/em&gt;, while not immediately implemented, is today the standard in all browsers and NodeJS. &lt;/p&gt;

&lt;p&gt;JavaScript Modules uses import and export statements to share code between files. &lt;/p&gt;

&lt;p&gt;There are multiple ways to export code.&lt;/p&gt;
&lt;h3&gt;
  
  
  Named Exports
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzs830rp6bidrqf9yodcl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzs830rp6bidrqf9yodcl.png" alt="Named Export Example" width="309" height="163"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is called a &lt;em&gt;named export&lt;/em&gt; and will export the add function. &lt;/p&gt;

&lt;p&gt;Using the below syntax, the function can be imported and used within another file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgsu0gxlblj9arud3573u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgsu0gxlblj9arud3573u.png" alt="Importing Named Export Example" width="587" height="187"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You also have the ability to export multiple named exports, like in the snippet below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6pxyp78pbh6cayc8tbit.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6pxyp78pbh6cayc8tbit.png" alt="Exporting multiple Named Exports Example" width="800" height="516"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;correspondingly, you would import these like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsq1zu7emldczoe94mlos.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsq1zu7emldczoe94mlos.png" alt="Importing Multiple Named Exports Example" width="800" height="248"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another useful trick is to rename a named export when importing it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu9wclpy6ztrcznafgn9o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu9wclpy6ztrcznafgn9o.png" alt="Renaming Import Example" width="800" height="308"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will allow two named exports with the same name, to be used in the same file and avoid variable collision. This is most common when using multiple third party code, where you don't have control over naming.&lt;/p&gt;
&lt;h3&gt;
  
  
  Default Exports
&lt;/h3&gt;

&lt;p&gt;Another way to export is using a default export. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhountp99646jrw7dd6pp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhountp99646jrw7dd6pp.png" alt="Default export example" width="800" height="263"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a sidenote, a default export can be named within the exporting file and it will work the same. The name you give it will have no effect when importing it. The below snippet would work just the same.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;pi&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Naming the default export &lt;em&gt;pie&lt;/em&gt; will work the same as &lt;em&gt;pi&lt;/em&gt;. It really doesn't matter how you alias a default import, as long as it isn't a JavaScript reserved word.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;pie&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./constants.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;radiusSquared&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;radius&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pie&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;radiusSquared&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A file can have only one default export by definition and when importing it, it can be aliased with any name. &lt;/p&gt;

&lt;p&gt;Another way that you will often see default exports used is with Object Property Shorthand. In the default export statement, an object literal will be created with all of the variables as the objects properties. The imported variable will be an object that contains all the exported functionality as the object's properties.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgqaz0j03rkar40h23qfs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgqaz0j03rkar40h23qfs.png" alt="Default Export Object Property Shorthand Example" width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And of course you can mix named and default exports.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpkpk0745is4bokcw3v2x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpkpk0745is4bokcw3v2x.png" alt="Mixed ExportsExample" width="800" height="226"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Module Object
&lt;/h3&gt;

&lt;p&gt;One last module pattern I will mention is creating a module object with the import. By using the syntax &lt;em&gt;import * as [object variable] from [source]&lt;/em&gt; you can wrap all of the imported functionality into a convenient object in the consuming code. '[object variable]' can be replaced with a variable name the contain the imported object. '[source]' can be replaced with the file location or the module identifier to indicate where the code lives.&lt;/p&gt;

&lt;p&gt;Take a look at the refactor below for an example. Now the consuming code is importing the functionality into an object being aliased as 'calculator', and has the methods 'add' and 'subtract' bundled into it. A nice way to keep your code a bit cleaner. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkqb0yzqgnp4ttsy3426s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkqb0yzqgnp4ttsy3426s.png" alt="Module Objects" width="660" height="612"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next article I will go into more details about module identifiers.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>es6</category>
      <category>modules</category>
      <category>node</category>
    </item>
  </channel>
</rss>
