Deno Libraries
Get up to speed using Deno ready-to-use libraries.
We'll cover the following
Standard library
Deno provides a comprehensive set of official modules audited and supported by the core team.
These modules are contained in a standard library to differentiate from third-party scripts uploaded by the community.
The standard library covers areas common in most projects, and it gets extended at each release.
For example:
Async
: For asynchronous tasksbytes
: Methods to manipulate bytes slicesdatetime
: Date/time functionsflags
: Parse command-line flagsfs
: Helpers to work with the filesystemhash
: Interfaces for hash functions.
deprecated in favor of the new Web Crypto API.http
: HTTP client/server functionsio
: I/O operationspath
: Path manipulation methodswasi
: WebAssembly System Interface implementation
Importing modules
While developing our programs, we should reference modules using a specific version. The same Deno team suggests that we avoid the latest release (master) as it might be unstable and introduce errors or side-effects to our code.
This is because the standard library is also shipped with each new version of Deno, and its master release might change at any moment. Therefore, as a best practice, we should always import specific versions to ensure stability.
Fixed versions are immutable.
This means that no further changes (patches or bug fixes) will be added to a specific version after its release.
// Do NOT do this
import { Logger } from "https://deno.land/std/log/logger.ts"
// Do this
import { Logger } from "https://deno.land/std@0.123.0/log/logger.ts"
Unstable APIs
We should know that not all modules from the standard library are in a stable state. It means that some of them use unstable Deno APIs. While the core team has already announced the purpose to solve this issue, it’s good to be aware of the current state and how to avoid console errors if they occur while developing.
If we use a method or module from the standard library relying on an unstable API, we need to add the --unstable
flag to prevent typescript errors when invoking the script:
deno run --allow-read --unstable target-file.ts
We can verify whether a specific API is unstable by accessing the lib.deno.unstable.d.ts
declaration of the release we’re using. There is a link to the master branch at the bottom of the lesson.
Third-party modules
Aside from the official Deno modules, a hosting service for Deno libraries (called deno.land/x
) is available with modules developed by the community.
It is a sort of Deno repository, collecting third-party modules stored on Github. It is a convenient way to search and use libraries created by the community.
⚠️ Note: Be aware that these sources are not audited by the Deno team. Therefore, we should always be careful before using a third-party script in our project.