运行节点index.js不会执行任何操作 [英] Running node index.js does nothing
问题描述
我正在尝试按照一个简单的教程来设置算法,该教程可以在这里找到.
没有成功消息.阿尔戈利亚一无所有.没有什么.我已经包含了我的代码,任何人都注意到我可能做错了什么.这使我沮丧了几个小时.
const algoliasearch = require('algoliasearch');const dotenv = require('dotenv');const firebase = require('firebase');//将目录中的.env文件中的值加载到process.env中dotenv.load();//配置firebasefirebase.initializeApp({databaseURL:process.env.FIREBASE_DATABASE_URL,});const database = firebase.database();//配置算法const algolia = algoliasearch(process.env.ALGOLIA_APP_ID,process.env.ALGOLIA_API_KEY);const index = algolia.initIndex(process.env.ALGOLIA_INDEX_NAME);//从Firebase获取所有联系人database.ref('/events').once('value',event => {console.log('索引为',索引);//建立所有记录的数组以推送到Algoliaconst records = [];event.forEach(event => {//从快照中获取密钥和数据const childKey = event.key;const childData = event.val();//我们将Algolia objectID设置为Firebase .keychildData.objectID = childKey;//添加对象以建立索引console.log('child data is',childData);records.push(childData);});//添加或更新新对象指数.saveObjects(记录).then(()=> {console.log('records are',records);console.log('导入Algolia的事件');}).catch(错误=> {console.error('将事件导入到Algolia时出错',错误);process.exit(1);});});
我已按照本教程中的所有步骤进行操作.我什至每次运行节点index.js时都再次运行它,无论我做什么都不会发生
问题与数据库链接有关.检查FIREBASE_DATABASE_URL的.env文件中的值,它应该类似于: https://test123-dsacb.firebaseio.com
I am trying to follow a simple tutorial on setting up algolia which one can find here.
https://www.algolia.com/doc/tutorials/indexing/3rd-party-service/firebase-algolia/
I literally copy the code word for word into an index.js file.
When I run node index.js in my terminal I get this
No success message. Nothing in algolia. Nothing. I have included my code is there anything that anyone noties that I may have done wrong. This has been frustrating me for hours.
const algoliasearch = require('algoliasearch');
const dotenv = require('dotenv');
const firebase = require('firebase');
// load values from the .env file in this directory into process.env
dotenv.load();
// configure firebase
firebase.initializeApp({
databaseURL: process.env.FIREBASE_DATABASE_URL,
});
const database = firebase.database();
// configure algolia
const algolia = algoliasearch(
process.env.ALGOLIA_APP_ID,
process.env.ALGOLIA_API_KEY
);
const index = algolia.initIndex(process.env.ALGOLIA_INDEX_NAME);
// Get all contacts from Firebase
database.ref('/events').once('value', event => {
console.log('index is', index);
// Build an array of all records to push to Algolia
const records = [];
event.forEach(event => {
// get the key and data from the snapshot
const childKey = event.key;
const childData = event.val();
// We set the Algolia objectID as the Firebase .key
childData.objectID = childKey;
// Add object for indexing
console.log('child data is', childData);
records.push(childData);
});
// Add or update new objects
index
.saveObjects(records)
.then(() => {
console.log('records are', records);
console.log('Events imported into Algolia');
})
.catch(error => {
console.error('Error when importing events into Algolia', error);
process.exit(1);
});
});
I have followed all steps in the tutorial. I even ran it again everytime I run node index.js nothing happens no matter what I do
The problem has to do with the database link. Check the value in the .env file of FIREBASE_DATABASE_URL , it should be something like: https://test123-dsacb.firebaseio.com
这篇关于运行节点index.js不会执行任何操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!