Using JSR with Node.js
Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine.
JSR packages can be used in Node.js by using JSR’s npm compatibility layer.
JSR packages are always ESM-only, so your project must be using
"type": "module" in your package.json to use JSR packages.
You can then add JSR packages using your package manager. This will add the
package to your package.json and install it into your node_modules folder
using your preferred package manager (npm, yarn, or pnpm).
# pnpm 10.9+ and yarn 4.9+
pnpm add jsr:@std/encoding
yarn add jsr:@std/encoding
# npm, bun, and older versions of yarn or pnpm
npx jsr add @std/encoding
bunx jsr add @std/encoding
yarn dlx jsr add @std/encoding
pnpm dlx jsr add @std/encodingNote: A
.npmrcfile is created when using the JSR CLI. The.npmrcfile that is created should be checked into source control. Without this, future calls tonpm install/yarn/pnpm install/bun installwill not succeed.
You can then import JSR packages in your code:
import { red } from "@std/fmt/colors";
console.log(red("Hello, world!"));Running this code will print a red “Hello, world!” text to your terminal.
node main.js