What is JSR?
JSR (JavaScript Registry) is the open-source package registry for modern JavaScript and TypeScript. It’s designed from the ground up to work seamlessly with modern JavaScript runtimes and provides native TypeScript support, better documentation, and improved security.JSR is the recommended package registry for Deno projects and is where the official Deno Standard Library is published.
Why JSR for the Standard Library?
The Deno Standard Library is published on JSR rather than npm for several key reasons:Native TypeScript
JSR packages are TypeScript-first, requiring no separate type definition files or compilation steps.
Better Documentation
Automatic generation of comprehensive API documentation from TypeScript types and JSDoc comments.
Cross-Runtime Support
Packages work across Deno, Node.js, Bun, and browsers with automatic compatibility handling.
Improved Security
Package provenance, signed packages, and transparency logs ensure package integrity.
How JSR Works with Deno
Deno has built-in support for JSR packages. When you import from the@std namespace, Deno automatically resolves and caches the package from JSR.
Import Resolution
jsr: prefix is optional for packages in the @std namespace, but you can use it explicitly if preferred.
Caching Behavior
When you import a JSR package:- Deno checks the local cache for the package
- If not cached, Deno downloads it from JSR
- The package is cached globally for reuse
- Subsequent imports use the cached version
Package Versioning on JSR
JSR packages follow semantic versioning (semver) and support flexible version constraints:Version Specifiers
Updating Dependencies
You can check for and update to newer versions:Working with deno.json
For better dependency management, define JSR imports in yourdeno.json configuration file:
Basic Configuration
Import Aliases
You can create custom aliases for standard library modules:Scoped Imports
Organize imports with path prefixes:Package Documentation on JSR
Every standard library package has comprehensive documentation on JSR:Accessing Documentation
- Visit jsr.io/@std
- Select a package (e.g.,
@std/path) - View:
- README and overview
- Complete API reference
- Usage examples
- Version history
- Source code links
Documentation Features
Auto-generated API Docs
Auto-generated API Docs
JSR automatically generates API documentation from TypeScript definitions and JSDoc comments.
Type Information
Type Information
Full TypeScript type definitions are displayed inline with documentation, showing function signatures, parameters, and return types.
Examples and Usage
Examples and Usage
Each function includes practical examples showing common use cases and expected outputs.
Symbol Search
Symbol Search
Search for specific functions, types, or constants across all standard library modules.
Publishing to JSR
While the standard library is maintained by the Deno team, you can publish your own packages to JSR:Creating a Package
Package Configuration
Publishing
JSR vs npm
While Deno supports both JSR and npm packages, there are key differences:| Feature | JSR | npm |
|---|---|---|
| TypeScript Support | Native | Requires @types packages |
| Documentation | Auto-generated from types | Separate docs site needed |
| Runtime Support | Deno, Node, Bun, browsers | Primarily Node.js |
| Import Syntax | ESM only | CommonJS and ESM |
| Package Signing | Built-in | Optional |
| Version Resolution | Semantic versioning | Semantic versioning |
When to Use Each
Use JSR
- New Deno projects
- TypeScript-first packages
- Modern JavaScript features
- Cross-runtime compatibility
Use npm
- Existing Node.js ecosystem
- Established packages
- Legacy compatibility
- Specific npm-only packages
Interoperability
JSR packages can work alongside npm packages in the same project:Deno’s built-in npm compatibility allows you to use JSR for modern packages while still accessing the npm ecosystem when needed.
Performance Considerations
Faster Downloads
JSR is optimized for fast package downloads:- CDN distribution worldwide
- Efficient compression
- Smart caching strategies
- Parallel downloads for dependencies
Module Resolution
JSR packages use ESM imports, which are:- Faster to parse than CommonJS
- Better for tree-shaking
- More compatible with modern bundlers
- Natively supported in browsers
Best Practices
Lock file usage
Lock file usage
Use
deno.lock to ensure consistent dependency versions across environments:Centralize imports
Centralize imports
Create a Then import from deps.ts:
deps.ts file to centralize external dependencies:Regular updates
Regular updates
Keep dependencies up to date to receive bug fixes and security patches:
Additional Resources
JSR Documentation
Complete guide to using and publishing on JSR
Standard Library
Browse all Deno standard library modules
Package Management
Learn more about managing dependencies in Deno
Configuration
Configure deno.json for your project