Windows告诉我,我的脚本中有语法错误,当我尝试运行它时,windows主机说在第1 char 1行有语法错误,经过检查和反复检查,我找不到错误,所以我尝试创建一个只打印hello world console.log("hello“)的脚本;这与相同的错误失败,所以我不知道问题是代码还是windows主机(我的机器),而且我的javascript知识基本上不存在。
const algoliasearch = require('algoliasearch')
const dotenv = require('dotenv')
const firebase = require('firebase');
const firestore = require('firebase/firestore');
// load values from the .env file in this directory into process.env
dotenv.load();
// initializes the firebase database.
firebase.initializeApp({
projectId: process.env.FIREBASE_PROJECT_ID,
databaseURL: process.env.FIREBASE_DATABASE_URL
})
const db = firebase.firestore();
// configure algolia
const algolia = algoliasearch(
process.env.ALGOLIA_APP_ID,
process.env.ALGOLIA_API_KEY
);
const index = algolia.initIndex(process.env.ALGOLIA_INDEX_NAME);
var docRef = db.collection(process.env.ALGOLIA_INDEX_NAME);
const records = [];
db.collection(process.env.ALGOLIA_INDEX_NAME).get()
.then((snapshot) => {
snapshot.forEach((doc) => {
// get the key and data from the snapshot
const childKey = doc.id;
const childData = doc.data();
// We set the Algolia objectID as the Firebase .key
childData.objectID = childKey;
// Add object for indexing
records.push(childData);
console.log(doc.id, '=>', doc.data());
});
// Add or update new objects
index.saveObjects(records).then(() => {
console.log('Documents imported into Algolia');
process.exit(0);
})
.catch(error => {
console.error('Error when importing documents into Algolia', error);
process.exit(1);
});
})
.catch((err) => {
console.error('Error getting documents', error);
});发布于 2018-04-12 11:58:24
这是一个节点JS应用程序,下面是在Windows上运行它的步骤。

app.js ),然后按Enter。
节点app.js
运行应用程序的结果将打印到命令提示符。https://stackoverflow.com/questions/49795798
复制相似问题