I'm working on a recipe website with React and using NedB as the database. For each recipe, I want to store an image that I can retrieve later to be able to show it on the website but can't find any resources online to know how to do it.
This is my current code for initializing the database and inserting the elements in it
const nedb = require("nedb");
class Recipes {
constructor(recipeFilePath) {
console.log(recipeFilePath);
if (recipeFilePath) {
this.recipes = new nedb(recipeFilePath);
console.log("recipes connected to " + recipeFilePath);
recipeFilePath;
} else {
this.recipes = new nedb();
}
}
init() {
this.recipes.insert({
id: "1",
name: "carrot cake",
description: "home made here",
category: "cake",
prep_time: 20,
cook_time: 30,
serving: 4,
ingredients: [],
rating: [],
photo_location:""
});
this.recipes.insert({
id: "1",
name: "carrot cake",
description: "home made here",
category: "cake",
prep_time: 20,
cook_time: 30,
serving: 4,
ingredients: [],
photo_location:""
});
}
getAllEntries() {
return new Promise((resolve, reject) => {
this.recipes.find({}, function (err, entries) {
if (err) {
reject(err);
} else {
resolve(entries);
console.log("function all() returns: ", entries);
}
});
});
}
}
module.exports = Recipes;
Can anyone elaborate on how to store images?