

* Download a file from the given `url` into the `targetFile`.This article was first published in March 2019 and was updated in November 2022.Ī common use case in JavaScript for HTML-to-PDF conversion is giving your website visitors the ability to download HTML content as a PDF file.

Here’s a sample function to download a file in Node.js: import Fs from 'fs' You can create a write stream piping the response data into a local target file. Determine whether the request is successful and pipe the response data into a local file. The response gives you access to the response status code, headers, and payload. The https.get method provides the response instance in a callback function. In this example, we’re using the file URL on the Internet and skip the request options because we don’t need them. The given https.get method accepts the resource URL and an options object. Node.js’ https module allows you to send requests HTTPS requests. Retrieve the List of Supported Hash Algorithms Join an Array of Strings to a Single String Value Sort an Array of Objects in JavaScript, TypeScript or Node.jsĬheck If a Value Is an Array in JavaScript or Node.js Sort an Array of Strings in JavaScript, TypeScript or Node.js How to Reverse an Array in JavaScript and Node.js Retrieve a Random Item From an Array in JavaScript or Node.js How to Exit, Stop, or Break an Array#forEach Loop in JavaScript or Node.js How to Get an Index in a for…of Loop in JavaScript and Node.js Split an Array Into Smaller Array Chunks in JavaScript and Node.js How to Exit and Stop a for Loop in JavaScript and Node.js Sort a Boolean Array in JavaScript, TypeScript, or Node.jsĬheck If an Array Contains a Given Value in JavaScript or Node.jsĪdd an Item to the Beginning of an Array in JavaScript or Node.jsĪppend an Item at the End of an Array in JavaScript or Node.js Sort an Array of Integers in JavaScript and Node.js Get an Array With Unique Values (Delete Duplicates) How to Run an Asynchronous Function in Array.map()Ĭlone/Copy an Array in JavaScript and Node.js
