Skip to content

Instantly share code, notes, and snippets.

View tjkhara's full-sized avatar

tjkhara

View GitHub Profile
@tjkhara
tjkhara / complex_app_3.md
Last active November 11, 2020 14:06
Complex App Note 3 - What is a controller?

What is a controller?

The router should not contain the functions.

Router should just be a list of routes.

Controller should have the functions.

In the root create dir controllers.

@tjkhara
tjkhara / complex_app_4.md
Last active November 11, 2020 16:10
Complex App Note 4 - What is a model?

What is a model?

Where we enforce rules or business logic.

User registration is what we are doing.

First we need to make sure that userController can access the data that is submitted in the form.

Go to app.js

@tjkhara
tjkhara / complex_app_5.md
Last active November 11, 2020 16:35
Complex App Note 5 - Adding validation to our model

Adding validation to our model

Part 1

Go to User.js

User.prototype.register = function(){
  // 1. Validate
	this.validate()

// 2. Only if there are not validation errors, then save user data into db

@tjkhara
tjkhara / complex_app_6.md
Created November 11, 2020 16:58
Misc clean up

Misc clean up

How to not accept things that are strings

model -> register function

call this.cleanUp()

Make this function above validate function

@tjkhara
tjkhara / complex_app_7.md
Last active November 11, 2020 17:50
Connecting to db in a reusable fashion

Connecting to db

Part 1

Save registered user into the db

model -> register function

validation is done now

@tjkhara
tjkhara / complex_app_8.md
Last active November 12, 2020 10:13
Letting users login

Login

Part 1

Find out which URL the html form submits to

views -> home-guest.ejs line 17 -> /login With the form submission the browser will send a post request to /login

@tjkhara
tjkhara / complex_app_9.md
Last active November 12, 2020 11:28
What is a promise?

What is a promise?

Go to model

User.prototype.login = function(){
  return new Promise((resolve, reject) => {
		this.cleanUp()
	  	usersCollection.findOne({username: this.data.username}, (err, attemptedUser) => {
		if(attemptedUser && attemptedUser.password == this.data.password){

resolve("congrats")

@tjkhara
tjkhara / heroku_deploy_error
Created December 8, 2020 13:55
Heroku deploy error for task manager api
tkhara@pop-os:~/envs/javascript_envs/task-manager$ git push heroku main
Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 4 threads
Compressing objects: 100% (15/15), done.
Writing objects: 100% (19/19), 38.52 KiB | 2.41 MiB/s, done.
Total 19 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
@tjkhara
tjkhara / local install error
Created December 8, 2020 16:31
Deleted the node modules folder and tried to npm install again node version 12.20.0
tkhara@pop-os:~/envs/javascript_envs/task-manager$ npm install
> [email protected] install /home/tkhara/envs/javascript_envs/task-manager/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
info sharp Using cached /home/tkhara/.npm/_libvips/libvips-8.7.0-linux-x64.tar.gz
prebuild-install WARN install No prebuilt binaries found (target=12.20.0 runtime=node arch=x64 libc= platform=linux)
make: Entering directory '/home/tkhara/envs/javascript_envs/task-manager/node_modules/sharp/build'
TOUCH Release/obj.target/libvips-cpp.stamp
CXX(target) Release/obj.target/sharp/src/common.o