Skip to content

Instantly share code, notes, and snippets.

View tjkhara's full-sized avatar

tjkhara

View GitHub Profile
@tjkhara
tjkhara / server.js
Created November 8, 2020 05:06
Simple html template with express
let express = require('express')
let app = express()
app.get('/', function(req, res){
res.send(`
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
@tjkhara
tjkhara / server.js
Created November 8, 2020 05:25
Simple express file with get and post - simple html template with bootstrap
let express = require('express')
let app = express()
app.use(express.urlencoded({extended: false}))
app.get('/', function(req, res){
res.send(`
<!DOCTYPE html>
<html>
@tjkhara
tjkhara / update_item.md
Last active November 9, 2020 05:32
Notes for updating an item

Updating an item

Things to revise and do

Setup

  • Click on the edit button to get the prompt
  • Get the user value and send it to the node server
  • Make a new file browser.js and put a link to that in the html that is returned
  • Create a public folder and create this file in it
@tjkhara
tjkhara / update_item_part_2.md
Last active November 9, 2020 16:50
Update item part 2

Update item part 2

Write node code to talk to the mongodb

Start work on this function in server.js

app.post('/update-item', function(req, res){
	// This is where the db communication will happen
	console.log(req.body.text)

res.send("Success")

@tjkhara
tjkhara / deleting_item.md
Last active November 9, 2020 17:20
Notes for deleting an item
@tjkhara
tjkhara / create_without_reload.md
Last active July 27, 2022 11:51
Creating a new item without page reload

Creating a new item without page reload

Intercept default behavior of submitting a form

Go to server.js and first add some ids:

let express = require('express')
let mongodb = require('mongodb') // Import mongodb package

let app = express()
@tjkhara
tjkhara / client_side_rendering.md
Created November 10, 2020 06:52
Client side rendering

Client side rendering

What is client side rendering?

On browser.js

function itemTemplate(item){
	return `<li class="list-group-item list-group-item-action d-flex align-items-center justify-content-between">
					<span class="item-text">${item.text}</span>
@tjkhara
tjkhara / complex_app_1.md
Last active November 11, 2020 13:08
Complex App Note 1

Complex App Getting Started Note 1

Need to improve:

  1. Code organization
  2. Different users
  3. Attention to detail - validation

Create new folder

@tjkhara
tjkhara / complex_app_2.md
Last active November 11, 2020 13:38
Complex App Note 1 - What is a router?

What is a router?

If you have an issue with

npm run watch

Do this

sudo pkill -f node