How to Download a File using Node Js?

12-Sep-2022

.

Admin

How to Download a File using Node Js?

Hello Friends,

In this tutorial, you will learn how to download a file using node.js. In this article, we will implement a how-to download a file using nodejs. you'll learn to download a file using nodejs. This post will give you a simple example of downloading a file using node js. So, let's follow a few steps to create an example of the nodejs download file.

I will give you a simple example of download a file using nodejs. In this example download a file using the download npm package in node js. There are multiple ways to download and save a file to the local filesystem in Nodejs.

So let's start following example with output:

Step 1: Install Node JS


This step is not required; however, if you have not created the node js app, then you may go ahead and execute the below command:

mkdir my-app

cd my-app

npm init

Step 2: Install Download Package

$ npm install download --save

Step 3: Update server.js file

server.js

const download = require('download')

// File URL

const url = `https://www.nicesnippets.com/image/nice-logo.png`

// Download the file

;(async () => {

await download(url, './')

})()

Run Node App

node serevr.js

I hope it can help you...

#Node JS