Docs / Guides
Try an npm package
Find a package on npm, read about it, add it, and call it in a Snippet.
Searching npm and reading about a package work in JSpark. Installing a package needs JSpark+. In JSpark, you can still use the packages that come with the Starters, and a web page can import from a CDN.
Find the package
- Click Packages on the rail, or choose Window → Packages.
- Type the package's name, or a word it is about, in Search npm….
- Click a result to open it.
Before you search, the list shows the packages already installed, such as those the Starters need.
Read about it
The package opens beside the list: its description and version, its size, when it was published, and its downloads a week. Under them is its README, as it is on npm. The npm link opens the package's page in your browser.
React is a JavaScript library for building user interfaces.
Required by the React Starter (^19). Stays while it’s here.
reactReact is a JavaScript library for creating user interfaces.
The react package contains only the functionality necessary to define React components. It is typically used together with a React renderer like react-dom for the web, or react-native for the native environments.
import { useState } from 'react';
import { createRoot } from 'react-dom/client';
function Counter() {
const [count, setCount] = useState(0);
return (
<>
<h1>{count}</h1>
<button onClick={() => setCount(count + 1)}>
Increment
</button>
</>
);
}Install it JSpark+
- Pick a version from the version menu, or keep the latest.
- Click Install.
The badge beside the name reads Installing…, then Building for Web…, then Installed and the version. One install serves every Node and Web Snippet. Two more badges say where the package works: Node and Web, each with a check, a cross or a question mark. Hover one to read why.
In JSpark, Install opens a message instead: Adding or changing packages needs JSpark+. Nothing is installed. See JSpark+.
Use it in a Snippet
- Open a Snippet, or press ⌘T or Ctrl+T for a new one.
- Import the package by its name, as in any Node project.
- Call it, and read the result in the console.
In a Node Snippet, importing a package usually keeps it out of Run as you type, because JSpark cannot tell what the package reaches. Press Run to run it. A few packages that only compute, such as date-fns and lodash, still run as you type. See Test code that reads files or calls an API.
The pictures show JSpark on a Mac. On Windows, the window looks a little different and uses Ctrl for ⌘, but everything works the same way.