// Import specific functions from a moduleimport { assertEquals, assertExists } from "@std/assert";// Import entire moduleimport * as path from "@std/path";// Import with version specifierimport { parse } from "@std/[email protected]";
Deno automatically resolves @std imports from JSR. No additional configuration is required.
The @std/fs module provides utilities for file system operations:
import { ensureDir, exists, copy } from "@std/fs";// Ensure a directory exists (creates if it doesn't)await ensureDir("./data/logs");// Check if a file or directory existsconst fileExists = await exists("./config.json");if (fileExists) { // Copy file to backup await copy("./config.json", "./config.backup.json");}
For production applications, it’s recommended to pin specific versions:
// Pin to exact versionimport { assertEquals } from "@std/[email protected]";// Pin to major version (receives minor and patch updates)import { join } from "@std/path@^1.0.0";// Pin to minor version (receives only patch updates)import { parse } from "@std/flags@~1.2.0";
In production, always pin to specific versions to ensure stability and prevent unexpected breaking changes.
Instead of importing entire modules, import only the functions you use. This improves tree-shaking and reduces bundle size.
// Goodimport { join, basename } from "@std/path";// Avoidimport * as path from "@std/path";
Use the latest stable versions
Regularly check for updates to standard library modules and update to the latest stable versions to get bug fixes and improvements.
# Check for outdated dependenciesdeno outdated
Leverage TypeScript types
The standard library is fully typed. Use TypeScript to catch errors early and improve code quality.
import { join } from "@std/path";// TypeScript will catch type errorsconst path: string = join("src", "main.ts");
Read module documentation
Each module has comprehensive documentation on JSR. Review the docs to understand all available functions and their usage.Visit jsr.io/@std to explore module documentation.