important-dawn-82568
06/03/2023, 1:12 AMdamp-forest-63651
06/04/2023, 6:14 PMimportant-dawn-82568
06/04/2023, 7:58 PMimportant-dawn-82568
06/04/2023, 7:58 PMacceptable-kangaroo-64719
06/05/2023, 10:20 AMimportant-dawn-82568
06/05/2023, 12:20 PMimportant-dawn-82568
06/05/2023, 8:35 PMjs
const express = require("express");
const admin = require("firebase-admin");
const serviceAccount = require("./credentials.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
const app = express();
app.post("/write-data", async (req, res) => {
try {
const db = admin.firestore();
const collectionRef = db.collection("collection_name");
const documentData = req.body;
const result = await collectionRef.add(documentData);
res.json({ success: true, documentId: result.id });
} catch (error) {
console.error("Error writing document:", error);
res
.status(500)
.json({ success: false, error: "Failed to write document to Firestore" });
}
});
const port = 3000; // Use the port provided by the environment or default to 3000
app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});
important-dawn-82568
06/05/2023, 8:37 PMjs
// Set the API endpoint URL
const apiUrl = 'http://localhost:3000/write-data'; // Replace with the actual URL of your server
// Prepare the request body
const requestBody = {
name: "test-name",
age: "test-age"
};
// Make the API request
fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
})
.then(response => {
if (response.ok) {
// Handle successful API response
return response.json();
} else {
// Handle API error response
throw new Error('API request failed');
}
})
.then(data => {
// Handle the API response data
console.log('API response:', data);
// Do further actions or send a message based on the response
})
.catch(error => {
console.error('Error calling API:', error);
// Handle the error
});
return {};
important-dawn-82568
06/05/2023, 8:37 PM22:32:41errorError executing action "inline-ins-3185f9d2f8.js" in flow:Employeur-français:node:Tell_info [ReferenceError, require is not defined]
and I don't get why... there is no import in the code that I run in botpressacceptable-kangaroo-64719
06/06/2023, 10:13 AM