Homework #15
- Once you open the app, you'll first want to start scraping articles from our tech source, TechCrunch
- Then, save the articles you'd like to keep for future reference
- Optionally, delete articles and add or delete individualized notes
- Scrape news stories from a given site (TechCrunch) and save selected data onto MongoDB
- Allow users to save and delete news stories as well as leave comments
- HTML
- CSS
- JavaScript
- Node.js
- Express.js
- Handlebars
- MongoDB
- Mongoose
- Cheerio
- The most satisfying part of the assignment was applying
async/await
to a function, which is a new JavaScript ES2017 feature. Instead of using the standard promise syntax, here we wait for mongoose to query the database and then move on to the rendering of the view. Thepopulate
method is chained to the initialfind
in order to translateObjectId
's into actual notes.
router.get('/', async function (req, res) {
var articles = await Article.find()
.sort({'_id': -1})
.populate('notes')
.exec(function (err, doc) {
if (err) throw err;
console.log(doc);
});
res.render('index', { articles: articles });
});