All Projects → ianmunrobot → 1702-express-review

ianmunrobot / 1702-express-review

Licence: other
Review repo for express.js and sequelize for Fullstack Academy/Grace Hopper Academy 1702 cohort

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to 1702-express-review

express-crud-router
Simply expose resource CRUD (Create Read Update Delete) routes for Express & Sequelize. Compatible with React Admin Simple Rest Data Provider
Stars: ✭ 109 (+211.43%)
Mutual labels:  sequelize, express-js
Online Bling
Stars: ✭ 9 (-74.29%)
Mutual labels:  sequelize, express-js
Express Sequelize Crud
Simply expose resource CRUD (Create Read Update Delete) routes for Express & Sequelize. Compatible with React Admin Simple Rest Data Provider
Stars: ✭ 65 (+85.71%)
Mutual labels:  sequelize, express-js
Crate
👕 👖 📦 A sample web and mobile application built with Node, Express, React, React Native, Redux and GraphQL. Very basic replica of stitchfix.com / krate.in (allows users to get monthly subscription of trendy clothes and accessories).
Stars: ✭ 2,281 (+6417.14%)
Mutual labels:  sequelize
Venture Management
一个包含vuejs和nodejs技术的全栈项目
Stars: ✭ 208 (+494.29%)
Mutual labels:  sequelize
sequelize-embed
Easily insert and update sequelize models with deeply nested associations
Stars: ✭ 15 (-57.14%)
Mutual labels:  sequelize
Middleman-NPM
Middleman is an intuitive Express performance monitor for all your middleware 🎉
Stars: ✭ 13 (-62.86%)
Mutual labels:  express-js
Connect Session Sequelize
Sequelize SessionStore for Express/Connect
Stars: ✭ 179 (+411.43%)
Mutual labels:  sequelize
shopify-node-express-app
Simple Shopify app with Express and Node.js that connects to a Shopify store via OAuth.
Stars: ✭ 20 (-42.86%)
Mutual labels:  express-js
MyAPI
A template to create awesome APIs easily ⚡️
Stars: ✭ 117 (+234.29%)
Mutual labels:  express-js
TypeScript-in-Nodejs-Starter
A starter kit for Node.js project written with TypeScript.
Stars: ✭ 39 (+11.43%)
Mutual labels:  sequelize
Express Starter
It's a hackathon-starter fork, but designed to use PostgreSQL by default (or MySQL)
Stars: ✭ 215 (+514.29%)
Mutual labels:  sequelize
HIMS
Hospital Information Management System create using Node Js
Stars: ✭ 41 (+17.14%)
Mutual labels:  express-js
Sequelize Auto
Automatically generate bare sequelize models from your database.
Stars: ✭ 2,494 (+7025.71%)
Mutual labels:  sequelize
2019-15
Catch My Mind - 웹으로 즐길 수 있는 캐치마인드
Stars: ✭ 19 (-45.71%)
Mutual labels:  sequelize
Cli
The Sequelize CLI
Stars: ✭ 2,248 (+6322.86%)
Mutual labels:  sequelize
nodefony
nodefony core framework
Stars: ✭ 19 (-45.71%)
Mutual labels:  sequelize
Typescript Express Starter
🚀 TypeScript Express Starter
Stars: ✭ 238 (+580%)
Mutual labels:  sequelize
Sequelize Docs Zh Cn
Sequelize 文档的中文版本: v4.42.0 | v5.21.5 | v6.6.5
Stars: ✭ 2,745 (+7742.86%)
Mutual labels:  sequelize
nestjs-api-mongoose
Collection example apps with NestJS and Typeorm, Sequelize, Mongodb, PostgreSQL, MySQL, GraphQL, Mercurius, etc. for the NestJS community 😻
Stars: ✭ 153 (+337.14%)
Mutual labels:  sequelize

1702 Express/Sequelize/Associations Review

Quick review session for 1702 FSA/GH students for Express and Sequelize and Sequelize association methods

To view the express only version of this repo, check out this branch

To view the express-sequelize version of this repo, check out this branch

Videos

Playlist for the video review of this repo being built can be found here

Individual Videos:

Express: Part 1 Part 2

Sequelize Part 1 - basic structure Part 2 - associations

NB: This was all live review, there may be some small inaccuracies in how things are described but I tried to repeat most of the questions for viewers

Starting up

To start up:

  • createdb puppies in the command line to create your postgres database
  • npm install to install node modules
  • npm run seed to seed your DB with the latest and greatest puppies/parks/locations/etc (this will clear/reset the db)
  • npm run seed:associations to seed some semi-randomized associations in your puppy instances
  • or
  • npm run seed:all to seed the instances and also the associations
  • npm start starts the server, you can now make requests to localhost:3000

Routes to try:

The server will start listening on localhost:3000 by default

Fire up an easy http client like Postman and try some routes like:

  • GET: /puppies
  • POST: /puppies
  • GET: /puppies/:id

Check out all the routers in /routes for more options!

Part 1: Express

Express Review questions

Dealing with queries and how to route them?

Dealing with multiple :params in the URI? How to make sure the right route?

What is static middleware???

Express routing:

Express is basically a big nested queue. Express goes through middleware and attempts to match the request path to middleware. If it matches an app.use sub-router on the way, it enters that sub-router and attemps to match against its

try {
// JS array notation is just shown here as a demo of the queue structure - express iterates through this and tries to match
[
  //matches this route
  app.use,
  //matches this route
  app.use,
  //if the path matches this /path, ener the router within which is another queue
  app.use('/path' [app.get, app.post]),
  // if the path matches this /path, enter
  app.use('/path2'),
  // match all paths and handle errors callback with 4 arguments
  app.use('*', function(4 arguments),
  // defaults to sending a 404 if no routes match
  app.use('*', function(req, res, next){ res.sendStatus(404)})
]
// if errors are caught, express helps handle
} catch(error) {
  res.status(500).send(error) // internal server error
}

Netflix and Express:

Cool article on Netflix using express servers and running into erro http://techblog.netflix.com/2014/11/nodejs-in-flames.html

Part 2: Sequelize

Questions:

  • Remind us which aspects are coming from Sequelize vs Express - where's the logic living? Where do I look in the docs - express or sequelize?

    • General answer: anything dealing with req or res is in express docs. Anything in a Sequelize promise chain that's not touching either req or res - look to the Sequelize Docs
  • Sequelize methods - what do we get and how do we use them?

Important Methods:

  • Model.findAll() finds all instances
  • Model.findAll({where: {.......}}) finds all instances that match the where condition
  • Model.findOne({where: {....}}) finds first match for the where condition
  • Model.findById(id) finds by an id number. Sequelize will coerce strings into ints, so you can simply use the req.params.id and not worry about casting to a Number before sending to Sequelize
  • Model.findOrCreate({where: {.....}}) will find an entry OR create it if necessary. returns Instance as first argument, and created boolean as the second. Good for making sure you don't make a bunch of duplicates
  • if the above queries return nothing, return value will be null

Part 3: Sequelize Association Methods:

For this segment of the review, we significantly changed the starting point from the previous ending point in order to save time during the live review. 3 new models were defined: Park, Location, and Food, with corresponding basic routers. The file structure was expanded so that there are separate /routes and /models folders. Seed data was also added in the seed.js and seedAssociations.js

This document explains more about the Sequelize methods and a bit more about what we aimed to do with this review session

You'll notice some new seeding files in this branch - this is to illustrate a bit about how to construct seed files, with or without associations

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].