Today’s modules have been:
- AJAX Rest API (geolocation, placing markers and boundaries and autocomplete)
- AJAX Rest API (hearting)
- AJAX Rest API (reviews, advanced aggregation)
- Pagination
- Deployment!!
nonobvious things to note:
- using location:
{$near: { $geometry: {type:'Point', coordinates}, $maxDistance: 10000}}}
- get current location
navigator.geolocation.getCurrentPosition
- zoom in on bounds:
const bounds = new google.maps.LatLngBounds();
,bounds.extend(position);
,map.setCenter(bounds.getCenter()); map.fitBounds(bounds);
- placing marker and infowindow on places
- using
google.maps.places.Autocomplete
- hearting uniquely:
const operator = hearts.includes(req.params.id) ? '$pull' : '$addToSet'
- hearting conditionally: use es6 params
const user = await User.findByIdAndUpdate(req.user._id,{[operator]: {hearts: req.params.id}},{new: true})
for a givenoperator
- adding a heart.js on the frontend to handle the ajax toggling of
hearted
class onclassList
property ofheart
element - reviewer stars css dark magic…
- mongoose virtual populate - mapping localfield to foreignfield
- mongoose virtual populate - wont be in the obj or json unless you define
toJSON: {virtuals: true}
in your schema setup - mongoose autopopulate - attached to
.pre('find', autopopulate)
- mongodb aggregation - $lookup (to map), $match (as a creative length filter), $project (to create a new field, aka $addField)
- pug: putting
element:
instead ofelement
means you can put the next element inline instead of on next line - pagination:
Model.find().skip(skip).limit(limit)
- dotenv:
"dotenv": "variables.env.now"
Deployment checklist
- git init, git add, git commit
- .gitignore
node_modules/
.DS_Store
*.log
.idea
haters/
variables.env
variables.env.now
- variables.env
- variables.env.now
- package.json start command
now
i have now finished wesbos’ class in a fairly epic sprint. he did a good job of abstracting the hard design decisions and explaining all the nifty mongodb and ajax tricks that would have taken ages to get through. emailing was also a highlight. I think that this is a solid base but really needs to be updated to use react/vue to be taken as a modern stack.
Problems with Learn Node:
- doesn’t use any modern frontend framework - unrealistic for serious development
- lacking polish - at end state, Maps page still doesnt find anything, Tags page doesn’t have pagination, hearts page pagination is broken, no delete button, etc
- unsatisfying ending, feels rushed.
Followups: