I just started learning Node.js with Express Framework, In my React application user sends an Image in base64
format, to the endpoint /session/start
, I want to store this base64
string and make it to buffer from another endpoint /session/recordFile
, I tried to declare a global variable but there is no positive results :), I have a question, what is an appropriate way to achieve this result using Express.js?
const express = require("express");
const axios = require("axios");
const Twitter = require("twitter");
const serverless = require("serverless-http");
const cors = require("cors");
const path = require("path");
const fs = require("fs");
const oauth = require("oauth");
let GlobalFile;
//start session
router.post("/session/start", function (req, res) {
const body = JSON.parse(req.body)
const file = body.binary
GlobalFile = file
});
router.get("/session/recordFile", function (req, res) {
const buf = Buffer.from(GlobalFile, 'base64')
res.send({mockFile: buf})
});