https://github.com/ecronix/functions-loader
A tool to load firebase functions directly from files
https://github.com/ecronix/functions-loader
Last synced: about 1 month ago
JSON representation
A tool to load firebase functions directly from files
- Host: GitHub
- URL: https://github.com/ecronix/functions-loader
- Owner: ecronix
- Created: 2024-09-09T18:47:22.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-09-09T19:18:45.000Z (8 months ago)
- Last Synced: 2024-09-09T23:49:38.283Z (8 months ago)
- Language: JavaScript
- Size: 67.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# functions-loader
`functions-loader` is a utility package designed to automatically load Firebase Cloud Functions from files and folders within the `functions` directory. This simplifies the process of organizing and deploying your cloud functions by dynamically importing them based on the file structure. It specifically loads files with the `.f.js` extension.
## Installation
To install `functions-loader`, you can use npm or yarn:
## Usage
To use `functions-loader`, you need to require it in your `index.js` or `main.js` file where you initialize your Firebase functions. The package will automatically load all functions from the `functions` directory that have the `.f.js` extension.
### Example
1. **Create your functions directory structure:**
```
functions/
├── index.js
├── helloWorld.f.js
└── user/
└── createUser.f.js
```2. **Initialize `functions-loader` in your `index.js`:**
```javascript
// functions/index.js
const { loadFunctions } = require("firebase-function-tools-preview");// Load all functions from the 'functions' directory
loadFunctions(__dirname, exports, true);
```3. **Define your cloud functions in separate files with the `.f.js` extension:**
```javascript
// functions/helloWorld.f.js
const functions = require("firebase-functions");module.exports = {
helloWorld: functions.https.onRequest((request, response) => {
response.send("Hello, World!");
}),
};
``````javascript
// functions/user/createUser.f.js
const functions = require("firebase-functions");module.exports = {
createUser: functions.auth.user().onCreate((user) => {
// Handle user creation
}),
};
```### Demo
You can find a complete example of how to use `functions-loader` in the `demo` folder of this repository. The demo includes a sample project structure and demonstrates how to set up and use the package to load Firebase Cloud Functions.
With this setup, `functions-loader` will automatically import and register all the functions defined in the `functions` directory and its subdirectories that have the `.f.js` extension.
## License
This project is licensed under the MIT License.