Skip to content
☁️ CLI tool to run Twilio Functions locally for development
TypeScript JavaScript Shell
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github docs(config.yml): Fix typos (#85) Oct 9, 2019
.vscode 🔧 Add vscode config Jul 18, 2018
__tests__ fix(debug): fix redaction of logger overwriting values (#79) Aug 30, 2019
bin feat: move project to TypeScript (#23) Jul 9, 2019
examples feat: move project to TypeScript (#23) Jul 9, 2019
fixtures/functions Improve functions error handling (#13) Jun 28, 2019
.all-contributorsrc chore(contributors): stefanjudis and philnash to contributors (#59) Jul 31, 2019
.gitignore feat: move project to TypeScript (#23) Jul 9, 2019
.npmrc chore(npm): remove message config for release Jul 10, 2019
.prettierrc feat: move project to TypeScript (#23) Jul 9, 2019
.travis.yml 👷 Add Travis Jul 17, 2018 chore(release): 2.1.1 Oct 3, 2019 docs: update links in CoC to https (#88) Oct 17, 2019 docs(contributing): add designated contributing guide Jul 9, 2019
LICENSE chore(license): update copyright notice Sep 25, 2019 docs(readme): link badges to npm (#89) Oct 17, 2019
commitlint.config.js chore: move to conventional commits Jul 9, 2019
jest.config.js feat: move project to TypeScript (#23) Jul 9, 2019
package-lock.json chore(release): 2.1.1 Oct 3, 2019
package.json chore(release): 2.1.1 Oct 3, 2019
tsconfig.base.json feat: move project to TypeScript (#23) Jul 9, 2019
tsconfig.json feat: introduce config file functionality (#15) (#38) Jul 26, 2019
tsconfig.test.json feat: move project to TypeScript (#23) Jul 9, 2019


CLI tool to locally develop and deploy to the Twilio Runtime. Part of the Serverless Toolkit

npm (scoped) npm GitHub All Contributors Code of Conduct PRs Welcome Travis (.com)


This project is part of the Serverless Toolkit. For a more extended documentation, check out the Twilio Docs.


You can install the CLI tool via npm or another package manager. Ideally install it as a dev dependency instead of global:

# Install it as a dev dependency
npm install twilio-run --save-dev

# Afterwards you can use by using:

npx twilio-run

# Or inside your package.json scripts section as "twilio-run"


# Create a valid project, for example:
npx create-twilio-function my-project

# Navigate into project
cd my-project

# Start local development server
twilio-run start

# Deploy to Twilio
twilio-run deploy


The CLI exposes a variety of commands. The best way to find out about the flags and commands available is to run twilio-run --help or twilio-run [command] --help

twilio-run start [dir]

  • Aliases: twilio-run dev, twilio-run

Starts a local development server for testing and debugging of your environment. By default only variables in the .env file will be available via process.env or through the context argument inside Twilio Functions.


# Serves all functions in current functions sub directory

# Serves all functions in demo/functions
twilio-run demo

# Serves functions on port 9000
PORT=9000 twilio-run

# Serves functions on port 4200
twilio-run --port=4200

# Starts up the inspector mode for the node process
twilio-run --inspect

# Exposes the Twilio functions via ngrok to share them
twilio-run --ngrok

twilio-run deploy

Deploys your project to Twilio. It will read dependencies automatically from your package.json's dependencies field and install them. It will also upload and set the variables that are specified in your .env file. You can point it against a different .env file via command-line flags.


# Deploys all functions and assets in the current working directory
twilio-run deploy

# Creates an environment with the domain suffix "prod"
twilio-run deploy --environment=prod

twilio-run list-templates

Lists the available templates that you can use to generate new functions and/or assets inside your current project with the twilio-run new command below.


# List available templates
twilio-run list-templates

twilio-run new [namespace]

Creates a new set of functions and/or assets inside your current project based on a template.


# Create a new function using the blank template
# in a subfolder (namespace) demo
twilio-run new demo --template=blank

twilio-run list [types]

Lists a set of available resources for different types related to your Account. Available resources that can be listed:

  • Services
  • Environments or Builds (requires to pass a Service)
  • Functions, Assets or Variables (requires to pass a Service and Environment)


# Lists all existing services/projects associated with your Twilio Account
twilio-run list services
# Lists all existing functions & assets associated with the `dev` environment of this service/project
twilio-run ls functions,assets --environment=dev --service-name=demo
# Outputs all environments for a specific service with extended output for better parsing
twilio-run ls environments --service-sid=ZSxxxxx --extended-output
# Only lists the SIDs and dates of last update for assets, variables and functions
twilio-run ls assets,variables,functions --properties=sid,date_updated

twilio-run activate

  • Aliases: twilio-run promote

Promotes an existing deployment to a new environment. It can also create a new environment if it doesn't exist.


# Promotes the same build that is on the "dev" environment to the "prod" environment
twilio-run activate --environment=prod --source-environment=dev
# Duplicates an existing build to a new environment called `demo`
twilio-run activate --environment=demo --create-environment --build-sid=ZB1234xxxxxxxxxx


The module also exposes two functions that you can use outside of the CLI tool to spin up local development.

If you want to interact with the Runtime API instead, check out the @twilio-labs/serverless-api package.

runDevServer(port: number, baseDir: string): Promise<Express.Application>

This allows you to trigger running an express server that will expose all functions and assets. Example:

const { runDevServer } = require('twilio-run');

  .then(app => {
    console.log(`Server is running on port ${app.get('port')})`);
  .catch(err => {
    console.error('Something failed');

handleToExpressRoute(handler: TwilioHandlerFunction): Express.RequestHandler

You can take the handler function of a Twilio Function file and expose it in an existing Express server. Example:

const express = require('express');
const bodyParser = require('body-parser');
const { handlerToExpressRoute } = require('twilio-run');

const { handler } = require('./path/to/function.js');

const app = express();
app.use(bodyParser.urlencoded({ extended: false }));


app.listen(3000, () => console.log('Server running on port 3000'));


This project welcomes contributions from the community. Please see the file for more details.

Code of Conduct

Please be aware that this project has a Code of Conduct. The tldr; is to just be excellent to each other ❤️


Thanks goes to these wonderful people (emoji key):

Dominik Kundel
Dominik Kundel


💻 🐛
Shelby Hagman
Shelby Hagman

🐛 💻
JavaScript Joe
JavaScript Joe

Stefan Judis
Stefan Judis

🐛 💻
Phil Nash
Phil Nash

🐛 💻 👀

This project follows the all-contributors specification. Contributions of any kind welcome!



You can’t perform that action at this time.