https://github.com/fahamutech/bfast-tools
CLI tools for BFast::Cloud platform. https://www.npmjs.com/package/bfast-tools
https://github.com/fahamutech/bfast-tools
bfast bfast-ee-cloud cli cloud faas faas-cli faas-platform functions functions-as-a-service nodejs nodejs-api nodejs-express nodeserver
Last synced: 2 months ago
JSON representation
CLI tools for BFast::Cloud platform. https://www.npmjs.com/package/bfast-tools
- Host: GitHub
- URL: https://github.com/fahamutech/bfast-tools
- Owner: fahamutech
- Created: 2019-11-02T05:47:19.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-12-31T06:33:29.000Z (6 months ago)
- Last Synced: 2025-03-23T21:01:37.806Z (3 months ago)
- Topics: bfast, bfast-ee-cloud, cli, cloud, faas, faas-cli, faas-platform, functions, functions-as-a-service, nodejs, nodejs-api, nodejs-express, nodeserver
- Language: JavaScript
- Homepage:
- Size: 3.37 MB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# bfast-tools
CLI tools for manage your project ( s ) in [BFast Cloud](https://bfast.mraba.co.tz).## Pre request
* Download and install [NodeJs](https://nodejs.org/en/download/) in your local PC. If you have it your good to go.
## Get stated
Install package from npm by run for linux: `sudo npm install -g bfast-tools`. For windows run: `npm install -g bfast-tools`## BFast::Cloud Projects
You use this sub command to manage your remote bfast projects. `bfast cloud` for more commands.
### Create a new project
Run the following command to create a new project
```shell script
josh@xps:~/Desktop$ bfast cloud create
```### List all projects
Run the following command to list all projects exist to your bfast cloud account
```shell script
josh@xps:~/Desktop$ bfast cloud list
```### Delete project
Run the following command to delete exist project to your bfast cloud account
```shell script
josh@xps:~/Desktop$ bfast cloud delete
```### Add a member to you project
Run the following command to add exist user of bfast to your bfast cloud account
```shell script
josh@xps:~/Desktop$ bfast cloud add-member
```## BFast::Cloud Database
You can manage your database instance using this sub command `bfast database`.
### Switch dashboard on
You can switch a dashboard on for data browser.
```shell script
josh@xps:~/Desktop$ bfast database dashboard-on
```### Switch dashboard off
You can switch a dashboard off for data browser.
```shell script
josh@xps:~/Desktop$ bfast database dashboard-off
```### Open Database Playground
You must add manually a specif collection/table/domain to a realtime engine to subscribe to its events.
```shell script
josh@xps:~/Desktop$ bfast database playground
```## BFast::Cloud Functions
Write your system functions with zero effort. Sub command to manage your functions is `bfast functions`
or `bfast fs`### Create a workspace
run `bfast functions create `. For example.
```shell script
josh@xps:~/Desktop$ bfast functions create bfastDemoFaas
```after that navigate inside your project directory.
```shell script
josh@xps:~/Desktop$ cd bfastDemoFaas
josh@xps:~/Desktop/bfastDemoFaas$
```after that install dependencies
```shell script
josh@xps:~/Desktop/bfastDemoFaas$ npm install
```Inside your workspace folder you will find a following folder structure
```
.
|__ functions
| |__ .ignore
| |__ index.mjs
| |__ package.json
|__ bfast.json
```Open `index.mjs` in your favorite text editor. You will see a commented example.
File `bfast.json` contain information of your BFast::Cloud project.
### Write your custom functions
You use [bfastnode](https://www.npmjs.com/package/bfastnode) package from npm to write your functions
Choose text editor of your choice like VSCode or WebStorm. You can write your function is different ways.
Single callback function
```javascript
const {BFast} = require('bfastnode');exports.mySingleFunctionName = BFast.functions().onHttpRequest('/mySingleFunctionName',(request, response)=>{
// your business logic
response.send('your response');
}
);
```Many callback in array. Good if your apply a middleware before execute finally logic. Refer to ExpressJS Middlware
```javascript
const {BFast} = require('bfastnode');exports.myArrayFunctionName = BFast.funtion().onHttpRequest('/myArrayFunctionName', [
(request, response, next)=>{
// middleware logic
request.query.from1 = 'query added in first callback';
next();
},
(request, response)=>{
// your business logic
response.send(request.query.from1);
}
]
);
```Mount express router. Your can use Express Router to manage complex routing. First run `npm install express` inside functions folder to add express module
```javascript
const express = require('express');
const router = express.Router();
const {BFast} = require('bfastnode');router.get('/', function (request, response) {
// your logic
response.send('get users');
});router.post('/user', function (request, response) {
// your logic
response.send('User saved');
})exports.functionNameUsingRouter = BFast.function().onHttpRequest('/functionNameUsingRouter',router);
```You can mount an express app too!. First run `npm install express` inside functions folder to add express module
```javascript
const express = require('express');
const app = new express();
const {BFast} = require('bfastnode');app.get('/', function (request, response) {
// your logic
response.send('get users');
});app.post('/user', function (request, response) {
// your logic
response.send('User saved');
})exports.functionNameUsingExpressApp = BFast.function().onHttpRequest('/functionNameUsingExpressApp', app);
```### Serve functions locally
In your current project folder, run following script
* Start a dev server ( auto restart when you change or edit a function )
```shell script
josh@xps:~/Desktop/bfastDemoFaas$ bfast functions serve --port 3000
```Or
```shell script
josh@xps:~/Desktop/bfastDemoFaas$ npm start
```* Start a static server which do not auto restart when you change or edit files in working directory
```shell script
josh@xps:~/Desktop/bfastDemoFaas$ bfast functions serve --port 3000 --static
```Default port is 3000, but you can change it by change a value of `port` option.
When everything is ok, you will see `BfastFunctions Engine Listening on 3000` or any port number you specify.
### Use functions you write
* If you use `path` field to specify address of your function you will use that path
* If your do not use `path` field the your function will be available in this format
`/function/`. For example by using curl
```shell script
josh@xps:~$ curl http://localhost:3000/functions/functionName
```
Or
```shell script
josh@xps:~$ curl http://localhost:3000/
```Or open your browser and enter `http://localhost:3000/functions/mySingleFunctionName` if you use `path` field
in your browser put this address http://localhost:3000/pathYouUseReplace `mySingleFunctionName` with a function name you want to call.
## Cloud Functions Deployment
You can deploy your functions to bfast cloud and host your server-less functions across our network.
#### Open Account
To publish your functions you must have a bfast cloud functions open one here [BFAST::CLOUD](http://bfast.mraba.co.tz).
After open account now you create your new project and you go to next step#### Login from your computer
Login from your computer by run.
```shell script
josh@xps:~/Desktop/bfastDemoFaas$ bfast user login
```#### Link your local project to remote bfast project
Run their following in your bfast local project folder
```shell script
josh@xps:~/Desktop/bfastDemoFaas$ bfast cloud link
```#### Set git environments
We use git to deploy your functions to bfast cloud function instance(s). Run thr following to set up git environments.
```shell script
josh@xps:~/Desktop/bfastDemoFaas$ bfast functions config
```#### To publish your functions
* Make sure you push all your production functions to `master` branch
* Then run
```shell script
josh@xps:~/Desktop/bfastDemoFaas$ bfast functions deploy
```*NOTE* You must push your project to a git repository you specify. BFast will look from master branch for functions.
#### Continuous Integration
* Generate token to use it for your favorite CI tool
```shell script
josh@xps:~/Desktop/bfastDemoFaas$ bfast user login:ci --username
```You can use token generated and example given to set your continuous integration
environment.**NOTE**
In CI mode you must set projectId manually to deploy your functions your can find projectId from your project console
in bfast cloud account## Notes To Take
* In this documentation we use port 3000, if you use a different port to run your functions replace 3000 with a port number you use in all examples found in this document to be relevant.
* You can create a javascript file anywhere inside functions folder or even create a sub folder and put your functions as illustrated above and bfast-tools package will discover your functions
## Help
Contact FahamuTech Team @Joshua Mshana ( [email protected] ) or leave an issue here at github