This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let hn = require('@datafire/hacker_news').create(); | |
(async () => { | |
let storyIDs = await hn.getStories({storyType: 'top'}); | |
let topStory = await hn.getItem({itemID: storyIDs[0]}); | |
console.log(`Top story: ${topStory.title} - ${topStory.url}`); | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let hn = require('@datafire/hacker_news').create(); | |
Promise.resolve() | |
.then(_ => hn.getStories({storyType: 'top'})) | |
.then(storyIDs => hn.getItem({itemID: storyIDs[0])) | |
.then(topStory => console.log(`Top story: ${topStory.title} - ${topStory.url}`)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note: this code doesn't work! | |
let hn = require('@datafire/hacker_news').create(); | |
hn.getStories({storyType: 'top'}, (err, storyIDs) => { | |
if (err) throw err; | |
hn.getItem({itemID: storyIDs[0]}, (err, topStory) => { | |
if (err) throw err; | |
console.log(`Top story: ${topStory.title} - ${topStory.url}`); | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note: this code doesn't work! | |
let hn = require('@datafire/hacker_news').create(); | |
let storyIDs = hn.getStories({storyType: 'top'}); | |
let topStory = hn.getItem({itemID: storyIDs[0]}); | |
console.log(`Top story: ${topStory.title} - ${topStory.url}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getThing(callback) { | |
api.getItem(1) | |
.then(item => setTimeout(_ => callback(null, item))) | |
.catch(e => setTimeout(_ => callback(e))); | |
} | |
getThing(function(err, thing) { | |
if (err) throw err; | |
console.log(thing); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getThing(callback) { | |
api.getItem(1) | |
.then(item => callback(null, item)) | |
.catch(e => callback(e)); | |
} | |
getThing(function(err, thing) { | |
if (err) throw err; | |
console.log(thing); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
api.getItem(1) | |
.then(item => { | |
delete item.owner; | |
console.log(item.owner.name); | |
}) | |
.catch(e => { | |
console.log(e); // Cannot read property 'name' of undefined | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
api.getItem(1, (err, data) => { | |
if (err) throw err; | |
item.amount++; | |
api.updateItem(1, item, (err, update) => { | |
if (err) throw err; | |
api.deleteItem(1, (err) => { | |
if (err) throw err; | |
}) | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Promise.resolve() | |
.then(_ => { | |
return api.getItem(1) | |
}) | |
.then(item => { | |
item.amount++ | |
return api.updateItem(1, item); | |
}) | |
.then(update => { | |
return api.deleteItem(1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs.readFile('index.html', 'utf8', (err, data) => { | |
if (err) throw err; | |
console.log(data); | |
}) |