# Developing with the Serverless Toolkit

> \[!NOTE]
>
> This means this project is 100% open-source. You can find its source code in the [Twilio Labs GitHub organization](https://github.com/twilio-labs).
>
> We currently don't support the projects through our official support channels. But you are welcome to reach out to us on GitHub for any questions, issues or suggestions or to contribute to this project.
>
> [Learn more about Twilio Labs](/docs/labs).

There are two ways you can use the [toolkit](/docs/labs/serverless-toolkit). If you are already using the Twilio CLI, you can install it via a plugin. Alternatively, you can use the toolkit as a standalone using twilio-run via npm or another Node.js package manager.

Throughout the docs we'll reference the Twilio CLI commands.

One of the primary goals of the Serverless Toolkit is to enable you to use your already existing development tools while developing Twilio Functions. With the built-in *start* command you can run a local development server that mimics the Twilio Functions and Assets environment and enables you to locally develop, test and debug your applications before deploying them to Twilio.

> \[!NOTE]
>
> The Toolkit is only emulating the environment that your Functions will be run
> in and as a result you might find some inconsistencies. It's always a good
> idea to additionally test your deployed Functions before putting them into a
> Twilio app. If you do find some inconsistencies, please [file an issue in our
> GitHub repository](https://github.com/twilio-labs/twilio-run/issues).

## Starting a local development server

If you are in a directory that follows the [folder structure of a Serverless Toolkit project](/docs/labs/serverless-toolkit/general-usage#project-structure), you'll be able to start your local development server with the basic command without any configuration.

```bash title="Run a Serverless project locally"
# Start the local development environment with live reloading of Functions
twilio serverless:start
```

This command will kick off the local development server and make any Functions and Assets that you have in your directory available for you.

By default the server will run in "live mode" meaning that any modifications to an existing Function will automatically reflect when do another request to the endpoint without you having to restart the server.

However, you will have to restart the server if you:

* Rename a file
* Create a new file
* Change your .env file

## Environment Variables

To have access to a configuration value via an environment variable or the `context` argument of your Twilio Function, you'll have to add it to the `.env` file in your project. We do not expose any system environment variables by default to make the experience as consistent as possible.

You can change the file that contains the environment variables using the `--env` flag and specifying a path to another `.env` file.

Alternative, use the `--load-local-env` flag to make your local environment variables available. These will not be uploaded during deployment though.

## Debugging your Functions

The *start* command provides the ability to start the Node.js debugger via a command-line flag. This allows you to use any debugger tool that supports Node.js to attach to it and use the debugging tools. For example [Visual Studio Code](https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_attaching-to-nodejs) or the [Chrome Developer Tools](https://medium.com/the-node-js-collection/debugging-node-js-with-google-chrome-4965b5f910f4).

The Toolkit supports both the `--inspect` flag as well as the `--inspect-brk` flag of Node.js. You can [read more](https://nodejs.org/api/cli.html#cli_inspect_host_port) about their possible values in the Node.js documentation.

```bash title="Start local development server in debug mode"
# Start a local development server with the Node.js debugger enabled
twilio serverless:start --inspect=""
```

## Exposing your localhost

While developing an application especially for Twilio, you might want to make your local development server available for others to access. For this, the Serverless Toolkit ships with [ngrok](https://ngrok.com) out of the box. You can use the `--ngrok`flag to enable it and if you are a paid customer of *ngrok*, you can set the value to a custom domain. For example: `--ngrok=twilio-demo`

```bash title="Start local development server with ngrok"
# Expose the local development server with a random ngrok URL
twilio serverless:start --ngrok=""
```

Once the server is started up and the ngrok connection is established, you'll be able to see the URLs printed in your terminal reflecting the new ngrok URLs as well as a link to the ngrok inspector.

## What's next?

Now that you know how to locally develop your Functions with the Serverless Toolkit, why not learn how you can do more with it.

* [Getting Started](/docs/labs/serverless-toolkit/getting-started)
  * [Install the toolkit](/docs/labs/serverless-toolkit/getting-started#install-the-twilio-serverless-toolkit)
  * [Explore available commands](/docs/labs/serverless-toolkit/getting-started#explore-the-commands-and-options)
* [General Usage](/docs/labs/serverless-toolkit/general-usage)
  * [Create a project](/docs/labs/serverless-toolkit/general-usage#create-a-project)
  * [Project structure](/docs/labs/serverless-toolkit/general-usage#project-structure)
  * [Start developing locally](/docs/labs/serverless-toolkit/general-usage#start-developing-locally)
  * [Create a new Twilio Function](/docs/labs/serverless-toolkit/general-usage#create-a-new-twilio-function)
  * [Deploy a project](/docs/labs/serverless-toolkit/general-usage#deploy-a-project)
* [Deploying](/docs/labs/serverless-toolkit/deploying)
* [Examples](/docs/labs/serverless-toolkit/examples)
* Guides
  * [Using Twilio Serverless with TypeScript](/docs/labs/serverless-toolkit/guides/typescript)
