> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lilbots.io/llms.txt
> Use this file to discover all available pages before exploring further.

# The JavaScript Runtime

> Build bots in JavaScript

Lil'bots provides a built in JavaScript runtime for bots based on [Deno](https://docs.deno.com/runtime/manual). If you have ever worked with Node.js, Deno should feel very familiar. This document will cover the basics of building bots in JavaScript.

## The script.mjs file & the main function

The entrypoint to your bot is the `script.mjs` file, as specified under the "main" property in the `botspec.json` file. When your bot is executed it will look for an exported `main` function in that file and call it.

The `main` function can be asyncrounous (to let you use await inside) and recieves the three following arguments:

* **`inputs`** (object) - the inputs passed to your bot by the user.
* **`params`** (object) - the parameters configured by the the user for your bot.
* **`accounts`** (array) - an array containing all the requested account credentials for your bot to use.

A basic `main` function will look like this:

```javascript theme={null}
export async function main(inputs, params, accounts) {
    // Your code here...
}
```

## Installing dependencies and packages

You may use external packages when building your bots - all you need to do is simply to import these packages, and the lil'bots runtime will automatically install them for you. There are a few sources of packages you may install:

* [**deno.land**](https://deno.land/x) (recommended) - fetching modules from denoland is the fastest way to get modules into your bot. Many NPM modules have a version hosted on denoland - so you may want to check there first whenever you need a module. Imports from denoland look like:

```javascript theme={null}
import OpenAI from "https://deno.land/x/openai@v4.24.1/mod.ts";
```

* [**esm.sh**](https://esm.sh/) - many NPM modules are also stored on the esm.sh CDN for fast downloads. You may install any ESM module like so:

```javascript theme={null}
import Module from "https://esm.sh/PKG@SEMVER[/PATH]";
```

* [**NPM Modules**](https://www.npmjs.com/) - you can also use any NPM module in your code. Just import it with an NPM prefix:

```javascript theme={null}
import { emojify } from "npm:node-emoji";
```

You can also specify a specific version by using the @version tag:

```javascript theme={null}
import { emojify } from "npm:node-emoji@2";
```

<Note>
  **Modules and Bot Speeds**

  Whenever you run your bot, lil'bots has to download all of it's dependencies - that's what happens when you see the "starting" startus on your bot run. For that reason, it is recommended to use few modules, and to install them from denoland / esm.sh to ensure fast start times.
</Note>

<Tip>
  **Module Caching**

  The lil'bots runtime caches modules for a certain period of time (for that reason, running the bot for a second time is sometime faster, as the modules are already cached). That means that many popular modules in their *latest* version are likely cached already - so it is recommended to use them over less common modules / specific versions.
</Tip>

<Info>
  **Required Binaries**

  Some NPM modules require certain binaries to be installed on the host OS. For instance, many media processing modules require FFMPEG to be installed. The lil'bots runtime has a set of installed binaries which you can find here.
</Info>
