Skip to content

Instantly share code, notes, and snippets.

View heytulsiprasad's full-sized avatar
⚛️
Overreacting

Tulsi Prasad heytulsiprasad

⚛️
Overreacting
View GitHub Profile
@heytulsiprasad
heytulsiprasad / User.js
Created July 11, 2020 19:31
Login authentication route using JWT
const mongoose = require("mongoose")
const Schema = mongoose.Schema
// Create Schema
const UserSchema = new Schema({
name: {
type: String,
required: true,
},
email: {
@heytulsiprasad
heytulsiprasad / status.md
Created July 12, 2020 06:34
Middleware to verify a route is authenticated or not

401

This means, authorization is denied.

400

This means, authorization can't be completed due to something wrong in the client side.

@heytulsiprasad
heytulsiprasad / howToProp.md
Last active July 17, 2020 15:40
How to add prop types to a class component?

Let's say we have a class component named, Trees.

We can import proptypes as such. import PropTypes from "prop-types"

Way 1

Outside of component itself. Best for Functional Components.

@heytulsiprasad
heytulsiprasad / authActions.js
Last active July 12, 2020 21:06
Actions that we need to perform for basic React auth. (We use Redux)
// get user when needed by this
export const getUser = () => (dispatch, getState) => {
// User loading
dispatch({ type: "USER_LOADING"})
axios
.get('/api/auth/user', tokenConfig(getState))
.then(res => {
dispatch({
type: "USER_LOADED",
@heytulsiprasad
heytulsiprasad / mongo.md
Last active July 14, 2020 08:31
Notes on MongoDB

Making less costly queries

As an example, when we write db.students.find() and then do a forEach() loop over it, we are increasing the cost of the process as what we're doing is:

  • Fetching all students from to server
  • Running forEach on our server to filter data we need

To avoid getting uncessary data and decrease the load on our server we can do requests specific to our needs, like these.

db.students.find({}, {name: 1, email: 0}) # values with 1 show up, 0 don't
@heytulsiprasad
heytulsiprasad / authorModel.js
Created July 14, 2020 08:39
Dealing with relational data inside schema (while making model)
const mongoose = require("mongoose")
const Schema = mongoose.Schema
const BookSchema = new Schema({
title: String,
pages: Number
})
const AuthorSchema = new Schema({
name: String,

Definitely not comprehensive. This is meant to be a basic memory aid with links to get more details. I'll add to it over time.

Install

$ npm install mongoose --save

Connect

const mongoose = require('mongoose');
@heytulsiprasad
heytulsiprasad / check.md
Last active July 15, 2020 13:54
Checklist for Travel log app

Full Stack Travel Log

A full stack application to store / list places you have traveled.

TODO

  • Setup Server
    • Install Dependencies
    • Install / Setup Linter
  • Setup Express App
@heytulsiprasad
heytulsiprasad / idea.md
Last active July 15, 2020 20:55
Travel Log application

Setup a Eslint config file

npx eslint --init

Common essential middlewares

  • Morgan: helps in logging server requests (dev and prod)
  • Helmet: removes unnecessary default server response and adds useful (most) secure headers
  • Cors: good ol' cors, allows access to make server requests
@heytulsiprasad
heytulsiprasad / design-resources.md
Last active July 30, 2022 07:03
Fork of design-resources repo by Brad