i created variable in app.post, and i want to use it in app.get, but before this i added this one to my database, but i don't know how to get access to this variable in other function, here is my code
const express = require("express");
const { default: mongoose } = require("mongoose");
const app = express();
const port = 3000;
const Task = require(`./models/task`);
require("./db/moongose");
// sendFile will go here
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(express.urlencoded({ extended: false }));
app.get("/task", (req, res) => {
res.render("../public/mainPage.ejs", {tasks: mongoose});
});
app.post("/task", async (req, res) => {
const task = new Task({
description: req.body.task,
});
try {
await task.save();
console.log(task.description);
res.redirect("/task");
} catch (e) {}
});
app.listen(port);
console.log("Server started at http://localhost:" + port);
and all i want to do is get acces to task.description in app.get