I have a node api where I need to take a input file which the user inputs. I am not sure what is the variable the input file will come in as. My curl command to test is :
curl -d "@data.csv" -X POST http://localhost:8085/Upload
My node function "upload" which I am writing is :
'use strict';
const express = require('express');
var fs = require('fs');
// Constants
const PORT = 8085;
const HOST = '0.0.0.0';
// App
const app = express();
app.get('/', (req, res) => {
res.send('Hello world\n');
});
app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);
app.post("/Upload", function(req, res) {
var rand = Math.floor(Math.random() * 100000) + 1;
console.log(rand);
// console.log(req);
// console.log(req.params)
var data = fs.readFileSync('input.txt');
console.log("Synchronous read: " + data.toString());
});
I am not sure how to access the variable file "data.csv"
which the user sends in nodejs code. This node code will again sends this "data.csv" to a different function. Please guide.