Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Quote:
http.get(options, function(res) {
res.on('data', function(data) {
file.write(data);
}).on('end', function() {
file.end();
console.log(file_name + ' downloaded to ' + DOWNLOAD_DIR);
});
});


where does on() come from?
where does 'data', and 'end' come from?

Sam

What I have tried:

From: <a href="https://www.hacksparrow.com/nodejs/using-node-js-to-download-files.html">Using Node.js to download files</a>[<a href="https://www.hacksparrow.com/nodejs/using-node-js-to-download-files.html" target="_blank" title="New Window">^</a>] 
Posted
Updated 18-May-20 4:14am

Node.js Events[^] may help you for an overall insignt on events.
HTTP | Node.js v14.2.0 Documentation[^] for the http package itself.
 
Share this answer
 
Thanks.

was able to see this now.

http.get(url[, options][, callback])

url <string> | <url>
options <object> Accepts the same options as http.request(), with the method always set to GET. Properties that are inherited from the prototype are ignored.
callback <function>

Returns: <http.clientrequest>

Since most requests are GET requests without bodies, Node.js provides this convenience method. The only difference between this method and http.request() is that it sets the method to GET and calls req.end() automatically. The callback must take care to consume the response data for reasons stated in http.ClientRequest section.

The callback is invoked with a single argument that is an instance of http.IncomingMessage.

url <string> | <url>
URL(input[, base])
input <string>
base <string> | <url>
URL.hash <string>
URL.host <string>
URL.hostname <string>
URL.href <string>
URL.origin <string>
URL.password <string>
URL.pathname <string>
URL.port <string>
URL.protocol <string>
URL.search <string>
URL.searchParams <urlsearchparams>
URLSearchParams(<string>)
<string>
URLSearchParams(<object>)
<object>
URLSearchParams(<iterable>)
<iterable>
URLSearchParams.append(name, value)
name <string>
value <string>
URLSearchParams.delete(name)
name <string>
<iterator> = URLSearchParams.entries()
<iterator>
URLSearchParams.forEach(fn[, thisArg])
fn <function>
thisArg <object>
<string> = URLSearchParams.get(name)
<string>
name <string>
<string[]> = URLSearchParams.getAll(name)
<string[]>
name <string>
<boolean> = URLSearchParams.has(name)
name <string>
<iterator> = URLSearchParams.keys()
URLSearchParams.set(name, value)
name <string>
value <string>
URLSearchParams.sort()
<string> = URLSearchParams.toString()
<iterator> = URLSearchParams.values()
URL.username <string>
URL.toString() <string>
URL.toJSON() <string>

[, options] from http.request() <object>
Object.agent http.Agent | <boolean>
Object.auth <string>
Object.createConnection agent.createConnection()
Object.defaultPort agent.defaultPort
Object.family <number>
Object.headers <object>
Object.host <string>
Object.hostname <string>
Object.insecureHTTPParser <boolean>
Object.localAddress <string>
Object.lookup dns.lookup()
Object.maxHeaderSize <number>
Object.method <string>
Object.path <string>
Object.port <number>
Object.protocol <string>
Object.setHost <boolean>
Object.socketPath <string>
Object.timeout <number>

[, callback(event)] from http.ClientRequest

Event: 'abort'
Event: 'connect'
connect.response http.IncomingMessage
connect.socket stream.Duplex
connect.head Buffer
Event: 'continue'
Event: 'information'
information.info <object>
info.httpVersion <string>
info.httpVersionMajor <integer>
info.httpVersionMinor <integer>
info.statusCode <integer>
info.statusMessage <string>
info.headers <object>
info.rawHeaders <string[]>
Event: 'response'
response.response http.IncomingMessage
Event: 'socket'
socket.socket stream.Duplex
Event: 'timeout'
Event: 'upgrade'
upgrade.response http.IncomingMessage
upgrade.socket stream.Duplex
upgrade.head Buffer
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900