# JavaScript

Load a .rupaplay file from plain JavaScript or any bundler with mountFile and control the player it returns.

## Quick start

1. Install the player.

   ```sh
   npm i @rupamotion/player
   ```

2. Put `hero.rupaplay` (export as **Player file** in Rupamotion) in `public/` (or wherever your build serves static
   files), and an empty element in the page:

   ```html
   <div id="hero"></div>
   ```

3. Mount the file into it. `markup: "auto"` writes the file's markup into the empty element:

   ```js
   import { mountFile } from "@rupamotion/player/file";

   await mountFile(document.querySelector("#hero"), "/hero.rupaplay", { markup: "auto" });
   ```

That's it: the animation plays.

## Need control?

`mountFile` resolves `{ player }` or `{ error }`. Keep the player to control it:

```js
import { mountFile } from "@rupamotion/player/file";

const root = document.querySelector("#hero");
if (root) {
	const { player, error } = await mountFile(root, "/hero.rupaplay", { markup: "auto" });
	if (error) console.warn(error.message);
	else player.play();
}
```

`mountFile` never rejects: it resolves `{ player }` or `{ error }`. Call `player.destroy()` when you take the root out
of the page. See [control playback](/guides/control/), [events](/guides/events/) and [errors](/guides/errors/).
