Skip to content

Latest commit

 

History

History
40 lines (29 loc) · 1.11 KB

node.md

File metadata and controls

40 lines (29 loc) · 1.11 KB
title description
Using JSR with Node.js
Learn how to use JSR packages 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 with the jsr CLI. 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).

npx jsr add @std/fmt

Note: You should check the .npmrc file that is created into source control. Without this, future calls to npm install / yarn / pnpm install will 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

Learn more about using packages.