最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to create functions config variables in Node.js? - Stack Overflow

programmeradmin1浏览0评论

I'm trying to implement Algolia as explained: here.

There is a message that says: App ID and API Key are stored in functions config variables

const ALGOLIA_ID = functions.config().algolia.app_id;
const ALGOLIA_ADMIN_KEY = functions.config().algolia.api_key;
const ALGOLIA_SEARCH_KEY = functions.config().algolia.search_key;

I'm not familiar with Node.js at all. How should I create functions config variables? It should be another file or another function or both?

Thanks!

I'm trying to implement Algolia as explained: here.

There is a message that says: App ID and API Key are stored in functions config variables

const ALGOLIA_ID = functions.config().algolia.app_id;
const ALGOLIA_ADMIN_KEY = functions.config().algolia.api_key;
const ALGOLIA_SEARCH_KEY = functions.config().algolia.search_key;

I'm not familiar with Node.js at all. How should I create functions config variables? It should be another file or another function or both?

Thanks!

Share Improve this question edited Mar 7, 2018 at 13:08 Always Learner asked Mar 7, 2018 at 13:02 Always LearnerAlways Learner 3,0297 gold badges41 silver badges89 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

I get the feeling that the reasons the other answers may not be working for you is that you are looking for how to SET the config, as opposed to retrieving it.

If you don't have it already, you'll need to install the Firebase CLI, as per the steps in https://firebase.google./docs/cli/ .

with it installed, you can set up your config like so:

firebase functions:config:set algolia.app_id="YOUR_APP_ID_HERE"

You can set multiple variables at once by just separating them with spaces like so:

firebase functions:config:set algolia.api_id="YOUR_API_ID_HERE" algolia.search_key="YOUR_SEARCH_KEY_HERE"

To check you have the right config in there, you can also run:

firebase functions:config:get

Which should print out, in JSON format, the current config you have set.

The config variables are created using the firebase cli.

If you type firebase --help you will get an output which includes the following:

functions:config:clone [options]           clone environment config from another project
functions:config:get [path]                fetch environment config stored at the given path
functions:config:set [values...]           set environment config with key=value syntax
functions:config:unset [keys...]           unset environment config at the specified path(s)

What are you trying to achieve exactly ?

I think you missed a step, this part uses the cloud function from firebase. You can see here "Extending Cloud Firestore with Cloud Functions" https://cloud.google./firestore/docs/extend-with-functions

Which will help you to extend firestore with cloud functions, and here you have a tutorial to write your first cloud function: https://firebase.google./docs/functions/get-started

Once you have that, you will notice that you will create

const functions = require('firebase-functions');

Which then allow you to do:

functions.config()

This is your "functions config variables". I'm guessing if you load Algolia dependency, you will have access to

functions.config().algolia.xxx;
发布评论

评论列表(0)

  1. 暂无评论