95126/download-file-with-node-without-using-third-party-libraries
How do I download a file with Node.js without using third-party libraries?
I don't need anything special. I only want to download a file from a given URL, and then save it to a given directory.
Hii,
You can create an HTTP GET request and pipe its response into a writable file stream:
const http = require('http'); const fs = require('fs'); const file = fs.createWriteStream("file.jpg"); const request = http.get("http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg", function(response) { response.pipe(file); });
Hello @kartik, It's particularly useful if you're concerned ...READ MORE
Hello @kartik, nodejs v10.12 now supports this natively ...READ MORE
Hello @kartik, you can do this: fs.readFile(path.resolve(__dirname, 'settings.json'), 'UTF-8', ...READ MORE
Hello @kartik, To print stacktrace of Error in console in ...READ MORE
Hello @kartik, Try using click instead of focus. It seems to ...READ MORE
Hii, Try this: $.ajax({ url:url, type:"POST", ...READ MORE
Hello, For jQuery <1.9 $('#inputId').attr('readonly', true); ...READ MORE
Hii, Say you had radio buttons like these, ...READ MORE
Hello @kartik, Try: var fs = require('fs'); var dir = ...READ MORE
Hello @kartik, Try this: var fs = require('fs'); var dir ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.