Third-party modules
Examples of how to install and run a Deno package
Deno’s 3rd-party package registry is:
About
Deno can import modules 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 tooling like
deno info
anddeno doc
. deno.land also provides a web UI for viewing module documentation. It is available at doc.deno.land.deno.land also provides a simple public hosting service for ES modules that work with Deno. It can be found at deno.land/x. source
From deno.land/x:
What is deno.land/x?
deno.land/x is a hosting service for Deno scripts. It caches releases of open source modules stored on GitHub and serves them at one easy to remember domain.
deno.land/x is a URL rewriting service for Deno scripts.
The basic format of code URLs is
https://deno.land/x/MODULE_NAME@BRANCH/SCRIPT.ts
.If you leave out the branch, it will default to the module’s default branch, usually master.
Example page:
Web server
Demo of using the deno.land/x/oak/ module.
The Application
class wraps the serve()
function from the http
package.
Middleware is added with the .use()
method.
A Hello World server:
index.ts
import { Application } from "https://deno.land/x/oak/mod.ts"; const app = new Application(); app.use((ctx) => { ctx.response.body = "Hello World!"; }); await app.listen({ port: 8000 });
Run:
$ deno run --allow-net index.ts
View in the browswer:
Colors
Demo of using the deno.land/x/color module.
index.ts
- using TypeScriptimport clc from 'https://deno.land/x/color/index.ts' console.log(clc.red.text("I am red")) console.log(clc.bgYellow.text("I am bgYellow")) console.log(clc.reset.text("I am reset")) console.log(clc.bright.text("I am bright"))
index.js
- JavaScript alternative.import clc from 'https://deno.land/x/color/index.js' console.log(clc.red.text("I am red")) // ...