Skip to content

fahamutech/bfast-functions

BFast Function

npm version Build Status License: MIT Code Quality

BFast Function Banner

A serverless function engine for Node.js, built on top of Express.js and Socket.IO.

BFast Function provides a powerful and flexible way to build and deploy serverless functions. It's designed to be easy to use, with a simple and intuitive API.

Features

  • Easy to use: A simple and intuitive API for creating and deploying serverless functions.
  • Flexible: Supports both HTTP and Socket.IO functions.
  • Scalable: Built on top of Express.js and Socket.IO, which are known for their scalability.
  • Extensible: Can be easily extended with custom middleware and plugins.
  • Open-source: BFast Function is open-source and available on GitHub.

Getting Started

There are several ways to get started with BFast Function:

1. From npm:

The easiest way to get started is to install BFast Function from npm:

npm install bfast-function

2. From Git:

You can also clone the BFast Function repository from GitHub:

git clone https://github.com/bfast-cloud/bfast-function.git

Then, install the dependencies:

cd bfast-function
npm install

3. From a tarball:

You can also download a tarball of the BFast Function repository from the releases page.

Then, extract the tarball and install the dependencies:

tar -xvf bfast-function-*.tar.gz
cd bfast-function-*
npm install

Usage

  1. Create a functions folder:

    mkdir functions
  2. Create a function file (e.g., example.js):

    const bfast = require('bfast');
    
    exports.myHttpFunction = bfast.functions().onHttpRequest('/hello', (request, response) => {
        response.status(200).send('Hello, World!');
    });
    
    exports.mySocketFunction = bfast.functions().onSocketIO('echo', (request, response) => {
        response.emit('echo', request.body);
    });
  3. Start the BFast Function engine:

    Create an index.mjs file in your root workspace and start the Faas server:

    import {start} from 'bfast-function';
    
    start({
        port: '3000',
        functionsConfig: {
            functionsDirPath: './functions',
        }
    }).catch(console.log);

    Then, start the server:

    node index.mjs

Docker

You can also run the BFast Function engine in a Docker container.

1. Build the Docker image:

docker build -t bfast-function .

2. Run the Docker container:

docker run -p 3000:3000 bfast-function

This will start the BFast Function engine and expose it on port 3000.

You can also mount a local functions folder to the container:

docker run -p 3000:3000 -v $(pwd)/functions:/app/functions bfast-function

This will mount the functions folder in your current working directory to the /app/functions folder in the container.

Configuration

The bfast.json file is a JSON file that contains configurations for the BFast Function engine.

{
  "ignore": ["**/node_modules/**"]
}
Key Type Description
ignore Array An array of glob patterns to ignore when loading functions.

API Reference

For a full list of available options and APIs, please see the API Reference.

Contributing

We welcome contributions to BFast Function! If you have an idea for a new feature or have found a bug, please open an issue on our GitHub repository.

License

BFast Function is licensed under the MIT License.

About

Cloud function node run-time for BFast::Cloud platform

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •