This is my code.
var admin = require("firebase-admin");
var serviceAccount = require("./service_key.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://capstone-resume-default-rtdb.asia-southeast1.firebasedatabase.app"
});
const firestore = admin.firestore();
const path = require("path");
const fs = require("fs");
const directoryPath = path.join(__dirname, "files");
fs.readdir(directoryPath, function(err, files) {
if (err) {
return console.log("Unable to scan directory: " + err);
}
files.forEach(function(file) {
var lastDotIndex = file.lastIndexOf(".");
var menu = require("./files/" + file);
menu.forEach(function(obj) {
firestore
.collection(file.substring(0, lastDotIndex))
.doc(obj.id)
.set(obj)
.then(function(docRef) {
console.log("Document written");
})
.catch(function(error) {
console.error("Error adding document: ", error);
});
});
});
});
This is the error that I'm getting.
SyntaxError: Invalid or unexpected token
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at /Users/prajwol/Capstone/uploader.js:23:16
at Array.forEach (<anonymous>)
at /Users/prajwol/Capstone/uploader.js:20:9
Also, my JSON document looks like this.
[
{
"id": "GOOGL1",
"company": "Google",
"title": " Software Engineer, Embedded Systems",
"experience": "5-8 Years",
"salary": "Not Disclosed",
"location": "Bengaluru/Bangalore",
"skills": "Analytical, Product management, SQL"
},
{
"id": "GOOGL2",
"company": "Google",
"title": " Data Manager, Cloud Delivery Center",
"experience": "4-8 Years",
"salary": "Not Disclosed",
"location": "Bengaluru/Bangalore",
"skills": "Analytical, Recruitment, Process improvement"
}
]