Deno Modules

Modules in deno are imported in both Javascript and Typescript using ES6 standard.

We can import and export deno modules using import and export keywords.

Import – Deno Modules

import keyword allows you to include and use modules held elsewhere, on your local file system, or remotely.

In order to import a module in Deno, we need to reference it by URL.

For example:

import { serve } from "https://deno.land/std/http/server.ts";

Export – Deno Modules

export keyword allows you to specify which parts of your module are accessible to users who import your module.

In order to export a module in Deno, we need to append the export keyword.

For example, here we are exporting a function named “add” from the math.ts typescript file.

Filename: math.ts

export function add(a: number, b: number): number {
  return a + b;
}

All functions, classes, constants, and variables which need to be accessible inside external modules must be exported.

That’s all about modules in deno.