I have multiple url's, pointing to different files. I want to be able to download them just by using the url string automatically with Javascript code, instead of manually going to the link and downloading them.
I have searched a lot of other answers on stackoverflow, few suggest creating an anchor tag in document body, but I am doing everything on backend not creating an index.html
edit: I am using next where for an api end point I am getting post requests, each which contains URL for a file which I have to download.
This is how I expect my POST request to come:
I want to be able to do something like this (in nextjs):
export default async function handler (req, res) {
if(req.method === "POST") {
let path = "./downloads/file"
await download(req.body.url, path)
}
}
Is the download
function possible, if so please help me with the implementation or provide any helpful packages to do the same.
axios
below solves my query. – venkata avinash appala