# Editor42 installed from NPM

> Live demo of the editor42 NPM package — the editor imported as a module and configured with base_url.

Source: https://editor42.com/examples/npm  
Section: Demo > Integrations > NPM  
Every page of editor42.com has a Markdown copy at its URL + `.md` (`index.md` after a URL that ends in `/`); all of them are in one file: https://editor42.com/llms-full.txt

## When to use

When your project has a bundler — Vite, Webpack, Rollup — and you want the editor to be a dependency like any other, versioned in your lockfile rather than fetched from a CDN at run time.

## How it works

`import editor42 from 'editor42'` and call `editor42.init()`. The one extra option is `base_url`: a bundler moves your code into a hashed file, so the editor cannot find its own skins, icons and plugins by itself. Point it at a copy of those folders in your public directory, or at the CDN, as this demo does.

## How to start using

Install the editor as a package and import it: `npm install editor42`. A bundler rewrites your code into a hashed file, so tell the editor where its skins, icons, themes and plugins live with `base_url` — your own copy of them, or the CDN.

See the [NPM install page](https://editor42.com/docs/install/npm) for both options.

- [Download ZIP](https://codeplay.democdn.com/pens/editor42/jPldiXa/editor42-example-npm.zip)
- [Open in CodePlay](https://codeplay.democdn.com/editor42/jPldiXa)

*The page shows these as tabs, one at a time: Live Demo, JavaScript, HTML, SASS.*

## Live Demo

[Live demo: Editor42 installed from NPM](https://run.codeplay.democdn.com/pens/editor42/jPldiXa/dist/index.html)

## JavaScript

```js
import editor42 from "editor42";

editor42.init({
  selector: "#editor",
  base_url: "https://cdn.editor42.com/editor42/latest",
  height: 460,
  menubar: false,
  plugins: "lists link code",
  toolbar: "undo redo | bold italic | bullist numlist | link code",
  content_style: `
    body { font-family: Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.6; }
  `
});
```

## HTML

```html
<h1>Editor42 from npm</h1>
<p class="hint">The <code>editor42</code> package, imported like any other dependency and bundled with your app.</p>

<textarea id="editor">
<h2>Installed from npm</h2>
<p>This editor was imported as a module: <code>import editor42 from 'editor42'</code>. No script tag, no global setup &mdash; your bundler treats it like any other package.</p>
<p>The one thing a bundler cannot do for you is guess where the editor's own files live, because it rewrites your code into a hashed bundle somewhere else. That is what <code>base_url</code> is for: it points at the folder holding <code>skins/</code>, <code>icons/</code>, <code>themes/</code>, <code>models/</code> and <code>plugins/</code>.</p>
<ul>
  <li>Point it at the CDN, as this demo does</li>
  <li>Or copy those folders into your own public directory and point it there</li>
</ul>
</textarea>
```

## SASS

```scss
.hint {
  margin-bottom: 20px;
  color: var(--demo-muted-color);
}
```
