Deno Modules: Usage, Best Practices & Node Module Imports

Learn about the Deno module system – the biggest workflow change you’ll encounter if you’re coming from Node.js. Find out how it works and how to use it, how to make use of Node.js packa…


This content originally appeared on SitePoint and was authored by Craig Buckler

Deno Modules

Learn about the Deno module system – the biggest workflow change you’ll encounter if you’re coming from Node.js. Find out how it works and how to use it, how to make use of Node.js packages in Deno, and more.

Node.js is a JavaScript runtime based on Chrome’s V8 engine, developed by Ryan Dahl, and released in 2009.

Deno is a JavaScript runtime based on Chrome’s V8 engine, developed by Ryan Dahl, and released in 2020. It was created with the benefit of a decade’s worth of hindsight. That doesn’t necessarily make it a sequel or superior to Node.js, but it deviates from that path.

See also:

The headline differences: Deno natively supports TypeScript, security, testing, and browser APIs. Module handling receives less attention, but it’s possibly the largest change to how you create JavaScript applications. Before discussing Deno, let me take you back to a simpler time…

Node.js Modules

JavaScript didn’t have a standard module system in 2009. This was partly because of its browser heritage and ES6 / ES2015 was several years away.

It would have been inconceivable for Node.js not to provide modules, so it adopted CommonJS from a choice of community workarounds. This led to the development of the Node Package Manager, or npm, which allowed developers to easily search, use, and publish their own JavaScript modules.

npm usage grew exponentially. It’s become the most popular package manager ever devised and, by mid-2020, hosts almost 1.5 million modules with more than 800 new ones published every day (source: modulecounts.com).

Deno Modules

Deno opts for ES2015 Modules which you import from an absolute or relative URL:

import { something } from 'https://somewhere.com/somehow.js';

The script at that URL must export functions or other values accordingly, e.g.

export function something() {
  console.log('something was executed');
}

Deno uses an identical module system to that implemented in modern web browsers.

Node.js also supports ES2015 modules … but it’s complicated and remains experimental. CommonJS and ES2015 modules look similar, but work in different ways:

Continue reading Deno Modules: Usage, Best Practices & Node Module Imports on SitePoint.


This content originally appeared on SitePoint and was authored by Craig Buckler


Print Share Comment Cite Upload Translate Updates
APA

Craig Buckler | Sciencx (2020-07-29T12:16:37+00:00) Deno Modules: Usage, Best Practices & Node Module Imports. Retrieved from https://www.scien.cx/2020/07/29/deno-modules-usage-best-practices-038-node-module-imports/

MLA
" » Deno Modules: Usage, Best Practices & Node Module Imports." Craig Buckler | Sciencx - Wednesday July 29, 2020, https://www.scien.cx/2020/07/29/deno-modules-usage-best-practices-038-node-module-imports/
HARVARD
Craig Buckler | Sciencx Wednesday July 29, 2020 » Deno Modules: Usage, Best Practices & Node Module Imports., viewed ,<https://www.scien.cx/2020/07/29/deno-modules-usage-best-practices-038-node-module-imports/>
VANCOUVER
Craig Buckler | Sciencx - » Deno Modules: Usage, Best Practices & Node Module Imports. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2020/07/29/deno-modules-usage-best-practices-038-node-module-imports/
CHICAGO
" » Deno Modules: Usage, Best Practices & Node Module Imports." Craig Buckler | Sciencx - Accessed . https://www.scien.cx/2020/07/29/deno-modules-usage-best-practices-038-node-module-imports/
IEEE
" » Deno Modules: Usage, Best Practices & Node Module Imports." Craig Buckler | Sciencx [Online]. Available: https://www.scien.cx/2020/07/29/deno-modules-usage-best-practices-038-node-module-imports/. [Accessed: ]
rf:citation
» Deno Modules: Usage, Best Practices & Node Module Imports | Craig Buckler | Sciencx | https://www.scien.cx/2020/07/29/deno-modules-usage-best-practices-038-node-module-imports/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.