Giter VIP home page Giter VIP logo

twilio-run's Introduction

npm npm npm Build Status All Contributors

☁️ twilio-run ☁️

CLI tool to run Twilio Functions locally for development

📦 Installation

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:
$ node_modules/.bin/twilio-run

$ npx twilio-run

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

📖 Usage

  CLI tool to run Twilio Functions locally for development

  Usage
    $ twilio-run [dir]

  Options
    --load-local-env, -f Includes the local environment variables
    --env, -e [/path/to/.env] Loads .env file, overrides local env variables
    --port, -p <port> Override default port of 3000
    --ngrok [subdomain] Uses ngrok to create an outfacing url

  Examples
    $ twilio-run
    # Serves all functions in current functions sub directory

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

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

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

    $ twilio-run --env
    # Loads environment variables from .env file

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

🔬 API

The module also exposes two functions that you can use outside of the CLI tool:

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');

runDevServer(9000)
  .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.all(handlerToExpressRoute(handler));

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

💞 Contributing

💖 Please be aware that this project has a Code of Conduct 💖

  1. Fork the project
  2. Clone your own fork like this:
$ git clone [email protected]:dkundel/twilio-run.git
  1. Install the dependencies
$ cd twilio-run
$ npm install
  1. Make changes
  2. Test your changes by running
$ npm test
  1. Commit your changes and open a pull request

✨ Contributors

Thanks goes to these wonderful people (emoji key):


Dominik Kundel

💻

dbbidclips

💻 🐛

Shelby Hagman

🐛 💻

JavaScript Joe

🐛

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

📜 License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.