One of the core features of Deno is that it doesn’t rely on a centralized package server like Node.js did with npm. Anyone can publish a module to their own server and it’s very simply to use them, thanks to Deno resolving URLs for modules. Let’s see how to create, publish, and use our first Deno module.

What are Deno modules?

Deno modules are pieces of that you can download and use in your project, similar to Node.js packages. They can range from being a simple function to something complex like Oak, a middleware framework for Deno’s http module.

Deno provides a set of standard modules like the http module that are reviewed by the core Deno team. These are guaranteed to work along with a specific Deno version and live in the same denoland/deno repository where the Deno source code can be found.

The standard modules are hosted at deno.land/std and can be accessed via URLs like all other Deno-compatible ES modules.

But Deno also supports third-party modules like Oak that you can import from any location on the web, like GitHub, a personal webserver, or a CDN like pika.dev or jspm.io.

To make it easier to consume third party modules Deno provides some built in tools like deno info and deno doc. Additionally, Deno’s website also provides a web UI for viewing module documentation, available at doc.deno.land.

The website also provides a simple public hosting service for Deno-compatible ES modules that can be found at deno.land/x

Writing your Deno module

Before publishing, we need to write our module. We’re going to create a simple to reverse a sequence of words. If we input “This is fun” it will return “fun is This”. Very simple. Create a new folder and the file for your module in it:

mkdir reverse-words
cd reverse-words
touch mod.ts

#javascript #deno #typescript #vs code

Publish a Deno module in 3 steps
9.40 GEEK