MenuGuides / Try an npm package

Docs / Guides

Try an npm package

Find a package on npm, read about it, add it, and call it in a Snippet.

On this page

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

  1. Click Packages on the rail, or choose Window → Packages.
  2. Type the package's name, or a word it is about, in Search npm….
  3. 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.

The Packages window on react: the facts from npm, then the README.

Install it JSpark+

  1. Pick a version from the version menu, or keep the latest.
  2. 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.

date-fns is found, installed for Node and Web, and imported in a Snippet.

In JSpark, Install opens a message instead: Adding or changing packages needs JSpark+. Nothing is installed. See JSpark+.

Use it in a Snippet

  1. Open a Snippet, or press ⌘T or Ctrl+T for a new one.
  2. Import the package by its name, as in any Node project.
  3. Call it, and read the result in the console.
An installed package, imported by its name: date-fns adds 30 days and formats the date.

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 buttons are at the top right, the menus are in theMenu button at the left end of the tabs, and shortcuts use Ctrl where a Mac uses ⌘. The rest works the same way.

Esc

Type to search every docs page.

JSpark is downloading

When you open JSpark-Setup.exe, Windows may stop it once, because the installer isn’t code-signed yet. If the file came from jspark.app:

A blue Windows box, “Windows protected your PC”: Microsoft Defender SmartScreen prevented an unrecognised app from starting. Under it, the link More info, and the button Don’t run.

1Click More info.

The same box after More info: Application JSpark-Setup-1.4.0.exe, Publisher Unknown publisher, and the buttons Run anyway and Don’t run.

2Then click Run anyway.

You see this only once: updates install inside the app. More in Install JSpark.