I would like to get the content of the <title>
tag from any specified external page, using JavaScript. Specifically, this is using the Code app by Zapier (vanilla node.js v4.3.2), so additional libraries may not be supported.
fetch
is supported...
fetch('http://example.com/')
.then(function(res) {
return res.text();
})
.then(function(body) {
var output = {id: 1234, rawHTML: body};
callback(null, output);
})
.catch(callback);
Docs state: "Very important - be sure to use callback in asynchronous examples!"
I am learning JavaScript and have been searching and trying various methods for hours. I don't fully understand the two functions in the example - I only need to return a "title", not the full body.
I was using an API designed to get page titles, but it seems to be a bit flaky. So I am hoping I can get titles using plain code.