This is a Twilio Labs project
This means this project is 100% open-source. You can find its source code in the Twilio Labs GitHub organization.
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.
There are two ways you can use the 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.
Please 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.
If you are in a directory that follows the folder structure of a Serverless Toolkit project, you'll be able to start your local development server with the basic command without any configuration.
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
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
Alternative, use the
--load-local-env flag to make your local environment variables available. These will not be uploaded during deployment though.
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 or the Chrome Developer Tools.
The Toolkit supports both the
--inspect flag as well as the
--inspect-brk flag of Node.js. You can read more about their possible values in the Node.js documentation.
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 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:
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.
Now that you know how to locally develop your Functions with the Serverless Toolkit, why not learn how you can do more with it.