Importing & Exporting


To build composable programs, it is necessary to be able to import and export functions from other modules. This is accomplished by using ECMA script modules in Deno.

To export a function, you use the export keyword.
export function sayHello(thing: string) {
  console.log(`Hello, ${thing}!`);
You can also export types, variables, and classes.
export interface Foo {}
export class Bar {}
export const baz = "baz";
To import things from files other files can use the import keyword.
import { sayHello } from "./util.ts";
You can also import all exports from a file.
import * as util from "./util.ts";
Imports don't have to be relative, they can also reference absolute file or https URLs.
import { VERSION } from "";

Run this example locally using the Deno CLI:

deno run