API to fetch a file from a server in node Js

const express = require("express");
const app = express();
const fs = require("fs");
app.post('/request/csvfile', (req, res) => {


    req.on('data', function (result) {
    console.log("file reading...",result.toString());
        let stream = fs.createReadStream(`${result.toString()}`);

        stream.on('data', function (ans) {
console.log("file reading...");
            res.send(ans);
        })
        stream.on('error', function (err) {
            res.send("FILE_NOT_EXIST");
            console.log(err);
        });


    });

})
app.listen(3100);
console.log("server running at port 3100");

curl –location –request POST ‘http://localhost:3100/request/csvfile’ \
–header ‘Content-Type: text/plain’ \
–data-raw ‘product_1632761261.csv’

Leave a comment

Your email address will not be published. Required fields are marked *