├── .gitignore ├── .idea ├── WebdevPitampura2019December.iml ├── misc.xml ├── modules.xml ├── vcs.xml └── workspace.xml ├── Lecture01 ├── Intro_to_WebDev.pptx └── frontend-basics │ ├── index.html │ ├── script.js │ └── style.css ├── Lecture02 └── html-basics │ ├── audio.mp3 │ ├── formelements.html │ ├── iframes.html │ ├── index.html │ ├── lists.html │ ├── media.html │ ├── picture.jpg │ ├── tables.html │ ├── text.html │ └── video.mp4 ├── Lecture03 └── css-basics │ ├── box-model │ ├── index.html │ └── style.css │ ├── combinators │ ├── index.html │ └── style.css │ ├── intro │ ├── index.html │ └── style.css │ ├── pseudo-selectors │ ├── index.html │ └── style.css │ ├── selectors │ ├── index.html │ └── style.css │ └── visibility │ ├── index.html │ └── style.css ├── Lecture04 └── css-advanced │ ├── animations │ ├── index.html │ └── style.css │ ├── collapse-list │ ├── index.html │ └── style.css │ ├── pop-button │ ├── index.html │ └── style.css │ ├── transforms │ ├── index.html │ └── style.css │ └── transitions │ ├── index.html │ └── style.css ├── Lecture05 ├── 3dcss-cube │ ├── index.html │ └── style.css └── positioning │ ├── index.html │ └── style.css ├── Lecture06 ├── bomdom │ ├── index.html │ └── script.js ├── console │ ├── console1.txt │ ├── console2.txt │ ├── console3.txt │ └── console4.txt ├── fizzbuzz │ ├── index.html │ └── script.js ├── hof │ ├── index.html │ └── script.js ├── scopes │ ├── index.html │ └── script.js └── todolist │ ├── index.html │ └── script.js ├── Lecture07 ├── bootstrap │ ├── index.html │ └── style.css └── css-media-queries │ ├── index.html │ ├── media-queries-2 │ ├── index.html │ └── style.css │ ├── media-query-flexbox │ ├── index.html │ └── style.css │ └── style.css ├── Lecture08 └── js-2 │ ├── .vscode │ └── settings.json │ ├── hof │ ├── index.html │ ├── script.js │ └── script2.js │ ├── object-create │ ├── class.js │ ├── index.html │ ├── proto-chains.js │ └── script.js │ ├── oop │ ├── OopSample.cpp │ ├── OopSample.java │ └── a.out │ ├── pass-by │ ├── index.html │ └── script.js │ └── this │ ├── index.html │ └── script.js ├── Lecture09 ├── async-js │ ├── index.html │ └── script.js ├── node │ ├── index.html │ └── script.js └── using-jquery │ ├── index.html │ ├── jquery-3.4.1.js │ └── script.js ├── Lecture10 ├── browser-multifile │ ├── index.html │ ├── lib.js │ └── main.js ├── file-ops │ ├── mytext.txt │ ├── read.js │ └── write.js ├── file-sort │ ├── input1.txt │ ├── input2.txt │ ├── input3.txt │ ├── output.txt │ └── sort.js ├── node-intro │ └── index.js ├── node-multifile │ ├── index.html │ ├── lib.js │ └── main.js └── universal-multifile │ ├── index.html │ ├── lib.js │ └── main.js ├── Lecture11 ├── node-import │ ├── google-logo.png │ ├── package-lock.json │ ├── package.json │ └── try-request.js └── sort-with-promises │ ├── Fluent_API.pseudocode │ ├── input1.txt │ ├── input2.txt │ ├── input3.txt │ ├── output.txt │ ├── output2.txt │ ├── sort-async-await.js │ ├── sort-promise-how.js │ └── sort-promise.js ├── Lecture12 ├── .idea │ ├── Lecture12.iml │ ├── misc.xml │ ├── modules.xml │ ├── vcs.xml │ └── workspace.xml └── intro-express │ ├── google-logo.png │ ├── package-lock.json │ ├── package.json │ ├── server.js │ └── todolist.js ├── Lecture13 ├── ajax-todo │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── index.html │ │ ├── script-classic.js │ │ ├── script.js │ │ └── style.css │ └── server.js ├── ajax-with-express │ ├── .idea │ │ ├── .gitignore │ │ ├── ajax-with-express.iml │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── a.html │ │ ├── alert.js │ │ ├── b.html │ │ ├── index.html │ │ └── style.css │ └── server.js └── express-middlewares │ ├── package-lock.json │ ├── package.json │ ├── server.js │ ├── server2.js │ ├── server3.js │ └── server4.js ├── Lecture14 └── hbs-rendering │ ├── package-lock.json │ ├── package.json │ ├── public │ ├── jquery.js │ └── todo.js │ ├── server.js │ └── views │ ├── faq.hbs │ └── todo.hbs ├── Lecture15 ├── mysql-intro │ ├── README.md │ ├── package-lock.json │ ├── package.json │ └── query.js └── sequelize-with-mysql │ ├── package-lock.json │ ├── package.json │ ├── read.js │ └── write.js ├── Lecture16 └── intro-mongodb │ ├── .gitignore │ ├── package-lock.json │ ├── read-promises.js │ ├── write-promise.js │ └── write.js ├── Lecture17 ├── blog-project │ ├── controllers │ │ ├── articles.js │ │ └── users.js │ ├── data │ │ └── db.js │ ├── package-lock.json │ ├── package.json │ ├── routes │ │ └── api │ │ │ ├── articles.js │ │ │ ├── index.js │ │ │ └── profiles.js │ └── server.js └── session-management │ ├── db.js │ ├── package-lock.json │ ├── package.json │ ├── server.js │ └── views │ ├── login.hbs │ ├── profile.hbs │ ├── signup.hbs │ └── viewcounter.hbs ├── Lecture18 └── blog-project │ ├── README.md │ ├── controllers │ ├── articles.js │ └── users.js │ ├── data │ ├── blog.db │ └── db.js │ ├── middlewares │ └── auth.js │ ├── package-lock.json │ ├── package.json │ ├── routes │ └── api │ │ ├── articles.js │ │ ├── index.js │ │ ├── profiles.js │ │ ├── user.js │ │ └── users.js │ ├── server.js │ └── utils │ ├── random.js │ └── string.js └── Lecture19 └── websockets ├── package-lock.json ├── package.json ├── public ├── chat.js ├── index.html ├── jquery.js └── style.css └── server.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .idea/ 3 | .vscode/ 4 | 5 | -------------------------------------------------------------------------------- /.idea/WebdevPitampura2019December.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Lecture01/Intro_to_WebDev.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-blocks-archives/Webdev_Pitampura_2019_December/79d23ff5c1d9685bb215e1a58bdd1255461d52fd/Lecture01/Intro_to_WebDev.pptx -------------------------------------------------------------------------------- /Lecture01/frontend-basics/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 |

Heading 1

13 |

Heading 2

14 |

Heading 3

15 |

Heading 4

16 |
Heading 5
17 |
Heading 6
18 | normal text 19 |
20 | 21 |
22 |
23 |
24 |
25 | 26 | 27 | 28 | 29 | Google 30 | 31 |
32 |
33 |
34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Lecture01/frontend-basics/script.js: -------------------------------------------------------------------------------- 1 | let btn1 = document.getElementById('btn1') 2 | let var1 = document.getElementById('var1') 3 | let var2 = document.getElementById('var2') 4 | 5 | btn1.onclick = function() { 6 | let a = parseInt(var1.value) 7 | let b = parseInt(var2.value) 8 | if (isNaN(a) || isNaN(b)) { 9 | alert('Invalid input') 10 | return 11 | } 12 | let c = a + b 13 | alert('Sum is ' + c) 14 | } 15 | -------------------------------------------------------------------------------- /Lecture01/frontend-basics/style.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | color: red; 3 | } 4 | -------------------------------------------------------------------------------- /Lecture02/html-basics/audio.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-blocks-archives/Webdev_Pitampura_2019_December/79d23ff5c1d9685bb215e1a58bdd1255461d52fd/Lecture02/html-basics/audio.mp3 -------------------------------------------------------------------------------- /Lecture02/html-basics/formelements.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 |
11 | 12 |
13 | 14 |
15 | 16 |
17 | 18 |
19 | 20 |
21 | 22 | 28 | 29 |
30 |
31 | 32 | 33 |
34 | A 35 | C 36 | B 37 | D 38 |
39 | X 40 | Y 41 | Z 42 | 43 | 44 | -------------------------------------------------------------------------------- /Lecture02/html-basics/iframes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Lecture02/html-basics/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | text 11 | media 12 | lists 13 | tables 14 | 15 | 16 | -------------------------------------------------------------------------------- /Lecture02/html-basics/lists.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 |
    11 |
  1. sfhsfh
  2. 12 |
  3. sfhsf
  4. 13 |
  5. fgndgndgn
  6. 14 |
  7. ehethdh
  8. 15 |
  9. etheth
  10. 16 |
17 | 18 |
    19 |
  1. sfhsfh
  2. 20 |
  3. sfhsf
  4. 21 |
  5. fgndgndgn
  6. 22 |
  7. ehethdh
  8. 23 |
  9. etheth
  10. 24 |
25 |
    26 |
  1. sfhsfh
  2. 27 |
  3. sfhsf
  4. 28 |
  5. fgndgndgn
  6. 29 |
  7. ehethdh
  8. 30 |
  9. etheth
  10. 31 |
32 | 39 | 40 | 47 | 54 |
55 |
This is title 0
56 |
This is title 1
57 |
This is desc 1
58 |
This is title 2
59 |
This is desc 2
60 |
61 | 62 | 63 | -------------------------------------------------------------------------------- /Lecture02/html-basics/media.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Lecture02/html-basics/picture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-blocks-archives/Webdev_Pitampura_2019_December/79d23ff5c1d9685bb215e1a58bdd1255461d52fd/Lecture02/html-basics/picture.jpg -------------------------------------------------------------------------------- /Lecture02/html-basics/tables.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
sfgsdfgndfhfrjfghj
dgnrytughdghgdh
fgertdfdfgdgbdgfb
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
DayCars
Monday1000
Tuesday2000
49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /Lecture02/html-basics/text.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | This is bold text 11 |
12 | This is italic text 13 | This         is underline text 14 | To print a space, type   15 | 16 | To create a heading, write 17 | example: 18 |

Heading 1

19 | code: 20 | <h1>Heading 1

21 | 22 | strike through text 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Lecture02/html-basics/video.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-blocks-archives/Webdev_Pitampura_2019_December/79d23ff5c1d9685bb215e1a58bdd1255461d52fd/Lecture02/html-basics/video.mp4 -------------------------------------------------------------------------------- /Lecture03/css-basics/box-model/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | abcd 12 |
13 | a 14 |
15 | b 16 |
17 | c 18 |
19 |
20 |
21 | 22 |
23 | a 24 |
25 | b 26 |
27 | c 28 |
29 |
30 |
31 | 32 |
a
33 |
b
34 |
c
35 | 36 | 37 | -------------------------------------------------------------------------------- /Lecture03/css-basics/box-model/style.css: -------------------------------------------------------------------------------- 1 | div.x { 2 | border: solid black 1px; 3 | margin: 10px; 4 | } 5 | 6 | div.y { 7 | border: solid black 1px; 8 | padding: 10px; 9 | } 10 | 11 | div.z { 12 | margin-top: 10px; 13 | margin-bottom: 10px; 14 | } 15 | 16 | .outer { 17 | background-color: bisque; 18 | } 19 | 20 | .middle { 21 | background-color: pink; 22 | } 23 | 24 | .inner { 25 | background-color: azure; 26 | } 27 | -------------------------------------------------------------------------------- /Lecture03/css-basics/combinators/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 |
first div
12 |

this is a page

13 |
this is a div 14 |

a para in the div

15 | 24 |
25 |
26 | this is another div 27 |
28 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Lecture03/css-basics/combinators/style.css: -------------------------------------------------------------------------------- 1 | div { 2 | color: red; 3 | } 4 | 5 | div li { 6 | font-size: 20pt; 7 | } 8 | 9 | div > p { 10 | font-style: italic; 11 | } 12 | 13 | h1 + div { 14 | background-color: yellow; 15 | } 16 | 17 | div, p { 18 | border: solid black 1px; 19 | } 20 | -------------------------------------------------------------------------------- /Lecture03/css-basics/intro/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 18 | 19 | 20 |

This is a paragraph

21 |

Heading 4

22 |

This is a paragraph

23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Lecture03/css-basics/intro/style.css: -------------------------------------------------------------------------------- 1 | p { 2 | color: green; 3 | } 4 | h4 { 5 | color: yellow; 6 | } 7 | -------------------------------------------------------------------------------- /Lecture03/css-basics/pseudo-selectors/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 |
Click Me!
12 | 18 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Lecture03/css-basics/pseudo-selectors/style.css: -------------------------------------------------------------------------------- 1 | #click { 2 | padding: 20px; 3 | width: 100px; 4 | height: 100px; 5 | font-size: 20pt; 6 | color: white; 7 | background-color: blueviolet; 8 | } 9 | 10 | #click:hover { 11 | color: darkblue; 12 | background-color: blanchedalmond; 13 | } 14 | 15 | #click:active { 16 | font-size: 10pt; 17 | } 18 | 19 | #list1 :first-child { 20 | font-size: 20pt; 21 | } 22 | 23 | #list2 :nth-child(2n + 1) { 24 | color: green; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Lecture03/css-basics/selectors/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 |
This is a div
12 |
This is another div
13 |
And another one
14 |
Our final div
15 |
And another one
16 |
Our final div
17 |
And another one
18 |
Our final div
19 | 20 |

This is a paragraph

21 |

One more para

22 | 23 | This is a span of text and 24 | here is another one 25 | 26 | 27 | -------------------------------------------------------------------------------- /Lecture03/css-basics/selectors/style.css: -------------------------------------------------------------------------------- 1 | .right { 2 | text-align: right; 3 | color: red; 4 | } 5 | 6 | .big { 7 | font-size: 20pt; 8 | } 9 | 10 | #one { 11 | background-color: yellow; 12 | } 13 | 14 | div { 15 | font-family: sans-serif; 16 | } 17 | 18 | div.right { 19 | padding-right: 30px; 20 | color: blue; 21 | } 22 | -------------------------------------------------------------------------------- /Lecture03/css-basics/visibility/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 |
1
12 |
2
13 |
3
14 |
4
15 |
5
16 |
6
17 | 18 | 19 | -------------------------------------------------------------------------------- /Lecture03/css-basics/visibility/style.css: -------------------------------------------------------------------------------- 1 | div { 2 | height: 60px; 3 | width: 60px; 4 | margin: 10px; 5 | background-color: bisque; 6 | } 7 | 8 | #four { 9 | visibility: hidden; 10 | } 11 | 12 | #five { 13 | /* display: none; */ 14 | height: 0px; 15 | visibility: hidden; 16 | margin: 0px; 17 | } 18 | -------------------------------------------------------------------------------- /Lecture04/css-advanced/animations/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /Lecture04/css-advanced/animations/style.css: -------------------------------------------------------------------------------- 1 | div { 2 | height: 50px; 3 | width: 50px; 4 | margin: 20px; 5 | background-color: firebrick; 6 | animation: leftright 2s infinite; 7 | } 8 | 9 | .two { 10 | animation-timing-function: ease-in; 11 | } 12 | 13 | .three { 14 | animation-timing-function: ease-out; 15 | } 16 | 17 | .four { 18 | animation-timing-function: linear; 19 | } 20 | 21 | @keyframes leftright { 22 | 0% { 23 | animation-timing-function: ease-in; 24 | background-color: red; 25 | } 26 | 33% { 27 | animation-timing-function: ease-out; 28 | background-color: blue; 29 | transform: rotate(45deg); 30 | } 31 | 66% { 32 | background-color: green; 33 | } 34 | 100%{ 35 | background-color: red; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Lecture04/css-advanced/collapse-list/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /Lecture04/css-advanced/collapse-list/style.css: -------------------------------------------------------------------------------- 1 | ul ul { 2 | visibility: hidden; 3 | height: 0px; 4 | } 5 | 6 | li:hover > ul { 7 | visibility: visible; 8 | height: auto; 9 | } 10 | -------------------------------------------------------------------------------- /Lecture04/css-advanced/pop-button/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 |
Click Me!
12 | 13 | 14 | -------------------------------------------------------------------------------- /Lecture04/css-advanced/pop-button/style.css: -------------------------------------------------------------------------------- 1 | div { 2 | transition: 1s; 3 | height: 100px; 4 | width: 200px; 5 | font-size: 20pt; 6 | padding: 30px; 7 | margin: 100px; 8 | background-color: brown; 9 | border: solid black 4px; 10 | border-radius: 20px; 11 | color: white; 12 | box-shadow: 10px 10px 5px grey; 13 | } 14 | 15 | div:hover { 16 | transition: 2s; 17 | transform: translate(-8px, -8px); 18 | box-shadow: 18px 18px 8px grey; 19 | } 20 | 21 | div:active{ 22 | transition: 0.5s; 23 | transform: translate(4px, 4px); 24 | box-shadow: 6px 6px 3px grey; 25 | } 26 | -------------------------------------------------------------------------------- /Lecture04/css-advanced/transforms/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 |
1
12 |
2
13 |
3
14 |
4
15 |
5
16 |
6
17 |
7
18 |
8
19 |
9
20 |
10
21 |
11
22 | 23 | 24 | -------------------------------------------------------------------------------- /Lecture04/css-advanced/transforms/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin-left: 100px; 3 | } 4 | div { 5 | border: solid 2px red; 6 | background-color:aqua; 7 | height: 100px; 8 | width: 100px; 9 | margin: 20px; 10 | font-size: 20pt; 11 | } 12 | 13 | .two { 14 | transform: translate(30px, -40px); 15 | } 16 | 17 | .three { 18 | transform: scale(2, 0.5) 19 | /* height: 200px; 20 | width: 200px; */ 21 | } 22 | 23 | .five { 24 | transform: rotateY(80deg) 25 | } 26 | 27 | .seven { 28 | transform: skew(30deg, 30deg) 29 | } 30 | 31 | .nine { 32 | transform: scaleX(2) scaleY(1.5) skewX(10deg) skewY(20deg) 33 | } 34 | -------------------------------------------------------------------------------- /Lecture04/css-advanced/transitions/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 |
1
12 |
2
13 |
3
14 |
4
15 |
5
16 |
6
17 |
7
18 |
8
19 |
9
20 |
10
21 |
11
22 | 23 | 24 | -------------------------------------------------------------------------------- /Lecture04/css-advanced/transitions/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin-left: 100px; 3 | } 4 | div { 5 | border: solid 2px red; 6 | background-color: aqua; 7 | height: 100px; 8 | width: 100px; 9 | margin: 20px; 10 | font-size: 20pt; 11 | transition: 2s, height 4s, width 1s; 12 | } 13 | 14 | .two:hover { 15 | background-color: gold; 16 | } 17 | 18 | .three:hover { 19 | transform: scale(2) 20 | } 21 | 22 | .five:hover { 23 | height: 200px; 24 | width: 50px; 25 | } 26 | 27 | .seven:hover { 28 | transform: translateY(50px); 29 | /* margin-top: 50px; */ 30 | } 31 | -------------------------------------------------------------------------------- /Lecture05/3dcss-cube/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 |
13 |
14 |
1
15 |
2
16 |
3
17 |
4
18 |
5
19 |
6
20 |
21 |
22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Lecture05/3dcss-cube/style.css: -------------------------------------------------------------------------------- 1 | .scene { 2 | perspective: 500px; 3 | } 4 | .cube { 5 | transition: 1s; 6 | margin: 30px; 7 | padding: 30px; 8 | transform-style: preserve-3d; 9 | } 10 | 11 | .cube:hover { 12 | transform: rotateX(45deg); 13 | } 14 | 15 | .cube:active { 16 | transform: translateZ(-1000px); 17 | } 18 | 19 | .face { 20 | position: absolute; 21 | border: solid black 1px; 22 | height: 50px; 23 | width: 50px; 24 | background-color: orange; 25 | opacity: 0.5; 26 | font-size: 25pt; 27 | color: white; 28 | } 29 | 30 | .front { 31 | transform: translateZ(25px); 32 | } 33 | 34 | .back { 35 | transform: translateZ(-25px); 36 | } 37 | 38 | .left { 39 | transform: translateX(-25px) rotateY(90deg); 40 | } 41 | 42 | .right { 43 | transform: translateX(25px) rotateY(90deg); 44 | } 45 | 46 | .top { 47 | transform: translateY(-25px) rotateX(90deg); 48 | } 49 | 50 | .bottom { 51 | transform: translateY(25px) rotateX(90deg); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Lecture05/positioning/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
x
16 |
17 |
y
18 |
19 |
z
20 |
21 |
22 |
23 |
24 |
25 |
p
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | 38 |
39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Lecture05/positioning/style.css: -------------------------------------------------------------------------------- 1 | .outer { 2 | background-color: bisque; 3 | margin: 40px; 4 | border: solid brown 2px; 5 | padding: 10px 6 | } 7 | 8 | .inner { 9 | background-color: mediumvioletred; 10 | margin: 20px; 11 | height: 60px; 12 | width: 60px; 13 | border: solid white 2px; 14 | padding: 10px; 15 | color: white; 16 | } 17 | 18 | #x { 19 | position: relative; 20 | right: 50px; 21 | } 22 | 23 | #y { 24 | position: absolute; 25 | top: 10px; 26 | right: 50px; 27 | } 28 | 29 | #z { 30 | position: fixed; 31 | bottom: 50px; 32 | right: 50px; 33 | } 34 | 35 | #p { 36 | position: sticky; 37 | top: 50px; 38 | bottom: 50px; 39 | } 40 | -------------------------------------------------------------------------------- /Lecture06/bomdom/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 10 | 11 | 12 | 13 | 14 | 15 |

16 |

17 | 18 | 19 | -------------------------------------------------------------------------------- /Lecture06/bomdom/script.js: -------------------------------------------------------------------------------- 1 | console.log("hello") 2 | 3 | window.onload = function () { 4 | let name = document.getElementById('name') 5 | let greet = document.getElementById('greet') 6 | let para = document.getElementById('para') 7 | 8 | greet.onclick = function () { 9 | let a = document.createElement('a') 10 | a.setAttribute('href', 'https://codingblocks.com') 11 | a.innerHTML = 'Coding Blocks' 12 | para.appendChild(a) 13 | } 14 | 15 | // console.log(name) 16 | console.log(name.value) 17 | } -------------------------------------------------------------------------------- /Lecture06/console/console1.txt: -------------------------------------------------------------------------------- 1 | let x = 10 2 | undefined 3 | x 4 | 10 5 | typeof x 6 | "number" 7 | x = "hello" 8 | "hello" 9 | let a = [1,2,3] 10 | undefined 11 | a 12 | Array(3) [ 1, 2, 3 ] 13 | 14 | typeof a 15 | "object" 16 | Object 17 | function Object() 18 | 19 | delete a[0] 20 | true 21 | a.length 22 | 3 23 | a 24 | Array(3) [ undefined, 2, 3 ] 25 | 26 | let obj = {a:10, b:true,c:"Hello"} 27 | undefined 28 | obj 29 | Object { a: 10, b: true, c: "Hello" } 30 | 31 | obj.a 32 | 10 33 | delet obj.a 34 | SyntaxError: unexpected token: identifier 35 | debugger eval code:1:6 36 | delet obj[a] 37 | SyntaxError: unexpected token: identifier 38 | debugger eval code:1:6 39 | delete obj.a 40 | true 41 | obj 42 | Object { b: true, c: "Hello" } -------------------------------------------------------------------------------- /Lecture06/console/console2.txt: -------------------------------------------------------------------------------- 1 | 1 + "1" 2 | "11" 3 | "2" + 2 4 | "22" 5 | 1 + "1" + 1 6 | "111" 7 | 1 === "1" 8 | false 9 | 1 == "1" 10 | true 11 | '' === 0 12 | false 13 | '' == 0 14 | true 15 | true == 1 16 | true 17 | true == 0 18 | false 19 | true == 2 20 | false 21 | false == 0 22 | true 23 | false == 2 24 | false 25 | let a = [1,2,3] 26 | undefined 27 | a 28 | Array(3) [ 1, 2, 3 ] 29 | 30 | a.toString() 31 | "1,2,3" -------------------------------------------------------------------------------- /Lecture06/console/console3.txt: -------------------------------------------------------------------------------- 1 | "1" + (1+1) + "1" 2 | "121" 3 | [1,2] + [4,5] 4 | "1,24,5" 5 | "1" + 1+ 1 + "1" 6 | "1111" 7 | let obj = {a:10,b:true,c:"hello"} 8 | undefined 9 | obj 10 | Object { a: 10, b: true, c: "hello" } 11 | 12 | JSON.stringify(obj) 13 | "{\"a\":10,\"b\":true,\"c\":\"hello\"}" 14 | JSON.parse(obj) 15 | SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data 16 | debugger eval code:1:6 17 | obj 18 | Object { a: 10, b: true, c: "hello" } 19 | 20 | JSON.parse() -------------------------------------------------------------------------------- /Lecture06/console/console4.txt: -------------------------------------------------------------------------------- 1 | let obj = {a:10,b:20} 2 | undefined 3 | typeof obj 4 | "object" 5 | let str = JSON.stringify(obj) 6 | undefined 7 | str 8 | "{\"a\":10,\"b\":20}" 9 | typeof str 10 | "string" 11 | let arr = [1,2,3] 12 | undefined 13 | typeof arr 14 | "object" 15 | let obj = {} 16 | SyntaxError: redeclaration of let obj 17 | debugger eval code:1:1 18 | let obj1 = {} 19 | undefined 20 | typeof obj1 21 | "object" 22 | [] + {} 23 | "[object Object]" 24 | +[] -------------------------------------------------------------------------------- /Lecture06/fizzbuzz/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Lecture06/fizzbuzz/script.js: -------------------------------------------------------------------------------- 1 | window.onload = function () { 2 | let list = document.getElementById('list') 3 | let btn = document.getElementById('btn') 4 | let number = document.getElementById('number') 5 | 6 | // btn.onclick = function () { 7 | // let start = new Date().getTime() 8 | // let n = parseInt(number.value) 9 | // let listContent = '' 10 | 11 | // for (let i = 1; i <= n; i++) { 12 | // let print = '' 13 | // if (i % 3 == 0) print += 'fizz' 14 | // if (i % 5 == 0) print += 'buzz' 15 | // if (print == '') print += i 16 | 17 | // listContent += `
  • ${print}
  • ` 18 | // } 19 | // list.innerHTML = listContent 20 | // let end = new Date().getTime() 21 | 22 | // console.log(end - start) 23 | // } 24 | 25 | btn.onclick = function () { 26 | let start = new Date().getTime() 27 | let n = parseInt(number.value) 28 | 29 | for (let i = 1; i <= n; i++) { 30 | let print = '' 31 | if (i % 3 == 0) print += 'fizz' 32 | if (i % 5 == 0) print += 'buzz' 33 | if (print == '') print = i 34 | 35 | let item = document.createElement('li') 36 | item.innerText = print 37 | 38 | list.appendChild(item) 39 | } 40 | 41 | let end = new Date().getTime() 42 | 43 | console.log(end - start) 44 | } 45 | } -------------------------------------------------------------------------------- /Lecture06/hof/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Lecture06/hof/script.js: -------------------------------------------------------------------------------- 1 | function inner() { 2 | return "Name" 3 | } 4 | 5 | function outer(arg) { 6 | function greeter() { 7 | console.log("Greet" + arg()) 8 | } 9 | 10 | return greeter 11 | } 12 | 13 | let greet = outer(inner) 14 | greet() -------------------------------------------------------------------------------- /Lecture06/scopes/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Lecture06/scopes/script.js: -------------------------------------------------------------------------------- 1 | // let a = 20 2 | 3 | function greet() { 4 | // let a = 100 5 | if (true) { 6 | let a = 10 7 | console.log(a) 8 | } 9 | console.log(a) 10 | } 11 | 12 | greet() -------------------------------------------------------------------------------- /Lecture06/todolist/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Lecture06/todolist/script.js: -------------------------------------------------------------------------------- 1 | let tasklist = [] 2 | 3 | window.onload = function() { 4 | function refreshList() { 5 | list.innerHTML = '' 6 | for (let task of tasklist) { 7 | let newItem = document.createElement('li') 8 | newItem.className = '' 9 | newItem.innerText = task 10 | list.appendChild(newItem) 11 | } 12 | } 13 | 14 | function addNewTask() { 15 | tasklist.push(item.value) 16 | refreshList() 17 | localStorage.tasks = tasklist.join(',') 18 | } 19 | let item = document.getElementById('item') 20 | let list = document.getElementById('list') 21 | let btn = document.getElementById('btn') 22 | 23 | if (localStorage.tasks) { 24 | tasklist = localStorage.tasks.split(',') 25 | } 26 | refreshList() 27 | 28 | btn.onclick = addNewTask 29 | 30 | item.addEventListener('keyup', function(event) { 31 | if (event.keyCode == 13) { 32 | addNewTask() 33 | } 34 | }) 35 | } 36 | 37 | //https://2ality.com/2012/01/object-plus-object.html 38 | -------------------------------------------------------------------------------- /Lecture07/bootstrap/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |

    This is a page

    17 | 18 |

    Some sample text

    19 | 20 |
    21 |
    22 |
    23 |
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum"
    24 |
    25 |
    26 |
    27 |
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
    28 |
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
    29 |
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
    30 |
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
    31 |
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
    32 |
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
    33 |
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
    34 |
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
    35 |
    36 |
    37 |
    38 |
    39 |
    X
    40 |
    Y
    41 |
    42 |
    43 |
    A
    44 |
    45 |
    46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Lecture07/bootstrap/style.css: -------------------------------------------------------------------------------- 1 | .container .row { 2 | color: blue; 3 | } 4 | 5 | .abc { 6 | color: red; 7 | } 8 | -------------------------------------------------------------------------------- /Lecture07/css-media-queries/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 |
    12 | This is some very important text 13 | 14 | 15 | -------------------------------------------------------------------------------- /Lecture07/css-media-queries/media-queries-2/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 |
    12 | 13 | 14 | -------------------------------------------------------------------------------- /Lecture07/css-media-queries/media-queries-2/style.css: -------------------------------------------------------------------------------- 1 | div { 2 | background-color: red; 3 | height: 500px; 4 | width: 500px; 5 | margin: 50px; 6 | } 7 | 8 | 9 | @media (min-width: 500px) { 10 | div { 11 | background-color: black; 12 | } 13 | } 14 | 15 | 16 | @media (min-width: 600px) { 17 | div { 18 | background-color: green; 19 | height: 200px; 20 | width: 200px; 21 | } 22 | } 23 | 24 | 25 | @media (min-width: 700px) { 26 | div { 27 | background-color: blue; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Lecture07/css-media-queries/media-query-flexbox/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 |
    13 |
    14 |
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. 15 |
    16 |
    17 |
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
    18 |
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
    19 |
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
    20 |
    21 | 22 | 23 | -------------------------------------------------------------------------------- /Lecture07/css-media-queries/media-query-flexbox/style.css: -------------------------------------------------------------------------------- 1 | .item { 2 | padding: 30px; 3 | } 4 | 5 | @media (min-width: 500px) { 6 | .content { 7 | display: flex; 8 | flex-wrap: wrap; 9 | } 10 | .item { 11 | width: 45%; 12 | } 13 | } 14 | 15 | @media (min-width: 1000px) { 16 | .item { 17 | width: 30%; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Lecture07/css-media-queries/style.css: -------------------------------------------------------------------------------- 1 | div { 2 | background-color: red; 3 | height: 500px; 4 | width: 500px; 5 | margin: 50px; 6 | } 7 | 8 | .important { 9 | color: red; 10 | } 11 | 12 | @media (max-width: 700px) { 13 | div { 14 | background-color: blue; 15 | } 16 | } 17 | 18 | @media print { 19 | .important { 20 | font-weight: bold; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Lecture08/js-2/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "string": "cpp", 4 | "iosfwd": "cpp", 5 | "iostream": "cpp" 6 | } 7 | } -------------------------------------------------------------------------------- /Lecture08/js-2/hof/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Lecture08/js-2/hof/script.js: -------------------------------------------------------------------------------- 1 | function greeterGenerator(greeting) { 2 | function createGreeter(name) { 3 | function greet() { 4 | console.log(greeting + name) 5 | } 6 | 7 | return greet 8 | } 9 | 10 | return createGreeter 11 | } 12 | 13 | let helloGreeter = greeterGenerator('Hello ') 14 | let welcomeGreeter = greeterGenerator('Welcome ') 15 | 16 | let greet1 = helloGreeter('John') 17 | let greet2 = helloGreeter('Jane') 18 | let greet3 = welcomeGreeter('John') 19 | let greet4 = welcomeGreeter('Jane') 20 | -------------------------------------------------------------------------------- /Lecture08/js-2/hof/script2.js: -------------------------------------------------------------------------------- 1 | function runLoop(n, afterLoop) { 2 | for (let i = 1; i <= n; i++) { 3 | console.log('Running iteration ' + i) 4 | } 5 | if (typeof afterLoop === 'function') { 6 | afterLoop() 7 | } 8 | } 9 | 10 | 11 | runLoop(5, function () { 12 | console.log("Loop has been run now") 13 | }) 14 | -------------------------------------------------------------------------------- /Lecture08/js-2/object-create/class.js: -------------------------------------------------------------------------------- 1 | class Person { 2 | constructor(name, age) { 3 | this.name = name 4 | this.age = age 5 | } 6 | } 7 | 8 | class Student extends Person { 9 | constructor(name, age, grade) { 10 | super(name, age) 11 | this.grade = grade 12 | } 13 | } 14 | 15 | let p = new Person('John', 50) 16 | let s = new Student('Simon', 12, 6) 17 | -------------------------------------------------------------------------------- /Lecture08/js-2/object-create/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Lecture08/js-2/object-create/proto-chains.js: -------------------------------------------------------------------------------- 1 | let a = 123 2 | let b = 'fhj' 3 | let c = true 4 | let d = {x: 10} 5 | let e = [1,4,6] 6 | let f = function () { return 10 } 7 | -------------------------------------------------------------------------------- /Lecture08/js-2/object-create/script.js: -------------------------------------------------------------------------------- 1 | let a = { 2 | p: 10, 3 | q: 'asdsa', 4 | r: true, 5 | } 6 | 7 | let b = Object.create(a) 8 | b.x = 123 9 | b.y = 'fghj' 10 | b.z = false 11 | 12 | let c = Object.create(b) 13 | c.l = 364 14 | c.m = 'dh' 15 | c.n = true 16 | -------------------------------------------------------------------------------- /Lecture08/js-2/oop/OopSample.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Person { 4 | string name; 5 | public: 6 | int age; 7 | Person(string name, int age) { 8 | this->name = name; 9 | if (age < 0) this->age = this->getDefaultAge(); 10 | else this->age = age; 11 | } 12 | int getDefaultAge() { return 18; } 13 | }; 14 | 15 | class Student : public Person { 16 | int grade; 17 | public: 18 | Student( 19 | string name, 20 | int age, 21 | int grade 22 | ): Person(name, age) { 23 | this->grade = grade; 24 | } 25 | int getAge() { return age; } 26 | int getDefaultAge() { return 13; } 27 | }; 28 | 29 | int main () { 30 | Student* s = new Student("John", -10, 5); 31 | cout<getAge(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Lecture08/js-2/oop/OopSample.java: -------------------------------------------------------------------------------- 1 | class Person { 2 | String name; 3 | int age; 4 | public Person(String name, int age) { 5 | this.name = name; 6 | if (age < 0) { 7 | this.age = this.getDefaultAge(); 8 | } else { 9 | this.age = age; 10 | } 11 | } 12 | public int getDefaultAge() { return 18; } 13 | } 14 | 15 | 16 | class Student extends Person { 17 | int grade; 18 | Student s = this; 19 | public Student(String name, int age, int grade) { 20 | super(name, age); 21 | this.grade = grade; 22 | } 23 | public int getDefaultAge() { return 13; } 24 | } 25 | 26 | Student s = new Student("John", -10, 5); 27 | -------------------------------------------------------------------------------- /Lecture08/js-2/oop/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-blocks-archives/Webdev_Pitampura_2019_December/79d23ff5c1d9685bb215e1a58bdd1255461d52fd/Lecture08/js-2/oop/a.out -------------------------------------------------------------------------------- /Lecture08/js-2/pass-by/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Lecture08/js-2/pass-by/script.js: -------------------------------------------------------------------------------- 1 | function increment(a, b) { 2 | a[0] = a[0]+1 3 | b[0] = b[0]+1 4 | } 5 | 6 | let x = [10] 7 | let y = [11] 8 | 9 | increment(x, y) 10 | 11 | console.log(x) 12 | console.log(y) 13 | -------------------------------------------------------------------------------- /Lecture08/js-2/this/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Lecture08/js-2/this/script.js: -------------------------------------------------------------------------------- 1 | function printThis () { 2 | console.log(this) 3 | } 4 | 5 | printThis() 6 | 7 | let x = 100 8 | let y = function () {return 10 } 9 | 10 | let obj = { 11 | a: 10, 12 | b: 'asdsad', 13 | c: true, 14 | p: x, 15 | q: y, 16 | g: function () { 17 | printThis() 18 | }, 19 | h: function () { 20 | function printThis2() { 21 | console.log(this) 22 | } 23 | return printThis2 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Lecture09/async-js/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
    READY
    16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Lecture09/async-js/script.js: -------------------------------------------------------------------------------- 1 | let count = 0 2 | 3 | window.onload = function() { 4 | let btnCount = document.getElementById('btnCount') 5 | let btnWait = document.getElementById('btnWait') 6 | let btnBadWait = document.getElementById('btnBadWait') 7 | let divResult = document.getElementById('divResult') 8 | 9 | btnCount.onclick = function() { 10 | count++ 11 | console.log('count = ' + count) 12 | } 13 | 14 | btnBadWait.onclick = function () { 15 | let start = new Date().getTime() 16 | while (new Date().getTime() - 5000 < start) { 17 | } 18 | } 19 | 20 | btnWait.onclick = function() { 21 | divResult.innerText = 'WAITING' 22 | console.log(new Date().getTime()) 23 | setTimeout(() => { 24 | console.log(new Date().getTime()) 25 | divResult.innerText = 'DONE' 26 | }, 5000) 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Lecture09/node/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Lecture09/node/script.js: -------------------------------------------------------------------------------- 1 | console.log('Hello World') 2 | -------------------------------------------------------------------------------- /Lecture09/using-jquery/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Lecture09/using-jquery/script.js: -------------------------------------------------------------------------------- 1 | $(() => { 2 | 3 | let newtask = $('#newtask') 4 | let tasklist = $('#tasklist') 5 | 6 | $('#addtask').click(()=> { 7 | tasklist.prepend( 8 | $('
  • ').text(newtask.val()) 9 | ) 10 | newtask.val('') 11 | }) 12 | 13 | }) 14 | 15 | -------------------------------------------------------------------------------- /Lecture10/browser-multifile/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Document 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Lecture10/browser-multifile/lib.js: -------------------------------------------------------------------------------- 1 | function add(a,b) { 2 | return a + b; 3 | } -------------------------------------------------------------------------------- /Lecture10/browser-multifile/main.js: -------------------------------------------------------------------------------- 1 | console.log("the ssum of 10 and 20 is " + add(10,20)) -------------------------------------------------------------------------------- /Lecture10/file-ops/mytext.txt: -------------------------------------------------------------------------------- 1 | This is a new content -------------------------------------------------------------------------------- /Lecture10/file-ops/read.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | 3 | fs.readFile('mytext.txt',(err,data) => { 4 | if(err) throw err 5 | 6 | console.log(data.toString()) 7 | }) -------------------------------------------------------------------------------- /Lecture10/file-ops/write.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | 3 | let content = "This is a new content" 4 | 5 | console.log('before write') 6 | 7 | fs.writeFile('mytext.txt',content,(err) => { 8 | if(err) throw err 9 | 10 | console.log('successfully written') 11 | }) 12 | 13 | console.log('after writing') -------------------------------------------------------------------------------- /Lecture10/file-sort/input1.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 22 3 | 3 4 | 44 5 | 545 6 | 656 7 | 4232 8 | 5454 9 | 23 10 | 32 11 | 3244 12 | 535 13 | 342 14 | 435 15 | 34 16 | 2324 17 | 13 18 | 44 19 | 323 20 | 3243 21 | 43 22 | 321 -------------------------------------------------------------------------------- /Lecture10/file-sort/input2.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 4 3 | 545 4 | 56454 5 | 5 6 | 7 7 | 3 8 | 2 9 | 3 10 | 223 11 | 445 12 | 664 13 | 232 14 | 56567 15 | 4534 16 | 8799 17 | 5644 18 | 2122 19 | 32132435 20 | 1224 -------------------------------------------------------------------------------- /Lecture10/file-sort/input3.txt: -------------------------------------------------------------------------------- 1 | 43 2 | 3 3 | 575 4 | 998 5 | 76 6 | 353423 7 | 221 8 | 235 9 | 76543 10 | 12346 11 | 6543 12 | 45 13 | 54 14 | 34 15 | 654 16 | 345 17 | 543 18 | 23456 19 | 5432345 -------------------------------------------------------------------------------- /Lecture10/file-sort/output.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 3 5 | 3 6 | 3 7 | 4 8 | 5 9 | 5 10 | 7 11 | 13 12 | 22 13 | 23 14 | 32 15 | 34 16 | 34 17 | 43 18 | 43 19 | 44 20 | 44 21 | 45 22 | 54 23 | 76 24 | 221 25 | 223 26 | 232 27 | 235 28 | 321 29 | 323 30 | 342 31 | 345 32 | 435 33 | 445 34 | 535 35 | 543 36 | 545 37 | 545 38 | 575 39 | 654 40 | 656 41 | 664 42 | 998 43 | 1224 44 | 2122 45 | 2324 46 | 3243 47 | 3244 48 | 4232 49 | 4534 50 | 5454 51 | 5644 52 | 6543 53 | 8799 54 | 12346 55 | 23456 56 | 56454 57 | 56567 58 | 76543 59 | 353423 60 | 5432345 61 | 32132435 -------------------------------------------------------------------------------- /Lecture10/file-sort/sort.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const os = require('os') 3 | // os.EOL 4 | 5 | let arr = [] 6 | 7 | fs.readFile(__dirname + '/input1.txt',(err,data) => { 8 | arr = arr.concat(data.toString().split(os.EOL)) 9 | 10 | fs.readFile(__dirname + '/input2.txt',(err,data) => { 11 | arr = arr.concat(data.toString().split(os.EOL)) 12 | 13 | fs.readFile(__dirname + '/input3.txt',(err,data) => { 14 | arr = arr.concat(data.toString().split(os.EOL)) 15 | 16 | arr = arr.sort((a,b) => a - b) 17 | 18 | fs.writeFile(__dirname + '/output.txt',arr.join(os.EOL),(err) => { 19 | console.log(arr) 20 | if(err) throw err 21 | console.log('Done') 22 | }) 23 | }) 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /Lecture10/node-intro/index.js: -------------------------------------------------------------------------------- 1 | console.log('Hello world!!') -------------------------------------------------------------------------------- /Lecture10/node-multifile/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Document 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Lecture10/node-multifile/lib.js: -------------------------------------------------------------------------------- 1 | // function add(a,b) { 2 | // return a + b; 3 | // } 4 | 5 | const add = (a,b) => { 6 | return a + b; 7 | } 8 | 9 | function subtract(a,b) { 10 | return a - b; 11 | } 12 | 13 | if(typeof window === 'undefined') { 14 | module.exports = { 15 | add, 16 | subtract, 17 | } 18 | } -------------------------------------------------------------------------------- /Lecture10/node-multifile/main.js: -------------------------------------------------------------------------------- 1 | let lib; 2 | if(typeof window === 'undefined') { 3 | lib = require('./lib') 4 | }else { 5 | lib = {add} 6 | } 7 | 8 | // console.log(lib) 9 | 10 | console.log('The sum of 10 and 20 is ' + lib.add(10,20)) 11 | // console.log('The diff of 100 and 20 is ' + lib.subtract(100,20)) -------------------------------------------------------------------------------- /Lecture10/universal-multifile/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Document 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Lecture10/universal-multifile/lib.js: -------------------------------------------------------------------------------- 1 | function add(a, b) { 2 | return a + b 3 | } 4 | 5 | function subtract(a, b) { 6 | return a - b 7 | } 8 | 9 | if (typeof window === 'undefined') { 10 | module.exports = { 11 | add, 12 | subtract, 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lecture10/universal-multifile/main.js: -------------------------------------------------------------------------------- 1 | let lib; 2 | if(typeof window === 'undefined') { 3 | lib = require('./lib') 4 | }else { 5 | lib = this 6 | } 7 | 8 | // console.log(lib) 9 | 10 | console.log('The sum of 10 and 20 is ' + lib.add(10,20)) 11 | // console.log('The diff of 100 and 20 is ' + lib.subtract(100,20)) 12 | -------------------------------------------------------------------------------- /Lecture11/node-import/google-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-blocks-archives/Webdev_Pitampura_2019_December/79d23ff5c1d9685bb215e1a58bdd1255461d52fd/Lecture11/node-import/google-logo.png -------------------------------------------------------------------------------- /Lecture11/node-import/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-import", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "ajv": { 8 | "version": "6.11.0", 9 | "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.11.0.tgz", 10 | "integrity": "sha512-nCprB/0syFYy9fVYU1ox1l2KN8S9I+tziH8D4zdZuLT3N6RMlGSGt5FSTpAiHB/Whv8Qs1cWHma1aMKZyaHRKA==", 11 | "requires": { 12 | "fast-deep-equal": "^3.1.1", 13 | "fast-json-stable-stringify": "^2.0.0", 14 | "json-schema-traverse": "^0.4.1", 15 | "uri-js": "^4.2.2" 16 | } 17 | }, 18 | "asn1": { 19 | "version": "0.2.4", 20 | "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", 21 | "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==", 22 | "requires": { 23 | "safer-buffer": "~2.1.0" 24 | } 25 | }, 26 | "assert-plus": { 27 | "version": "1.0.0", 28 | "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", 29 | "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" 30 | }, 31 | "asynckit": { 32 | "version": "0.4.0", 33 | "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", 34 | "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" 35 | }, 36 | "aws-sign2": { 37 | "version": "0.7.0", 38 | "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", 39 | "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=" 40 | }, 41 | "aws4": { 42 | "version": "1.9.1", 43 | "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz", 44 | "integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==" 45 | }, 46 | "bcrypt-pbkdf": { 47 | "version": "1.0.2", 48 | "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", 49 | "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", 50 | "requires": { 51 | "tweetnacl": "^0.14.3" 52 | } 53 | }, 54 | "caseless": { 55 | "version": "0.12.0", 56 | "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", 57 | "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" 58 | }, 59 | "combined-stream": { 60 | "version": "1.0.8", 61 | "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", 62 | "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", 63 | "requires": { 64 | "delayed-stream": "~1.0.0" 65 | } 66 | }, 67 | "core-util-is": { 68 | "version": "1.0.2", 69 | "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", 70 | "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" 71 | }, 72 | "dashdash": { 73 | "version": "1.14.1", 74 | "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", 75 | "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", 76 | "requires": { 77 | "assert-plus": "^1.0.0" 78 | } 79 | }, 80 | "delayed-stream": { 81 | "version": "1.0.0", 82 | "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", 83 | "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" 84 | }, 85 | "ecc-jsbn": { 86 | "version": "0.1.2", 87 | "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", 88 | "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", 89 | "requires": { 90 | "jsbn": "~0.1.0", 91 | "safer-buffer": "^2.1.0" 92 | } 93 | }, 94 | "extend": { 95 | "version": "3.0.2", 96 | "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", 97 | "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" 98 | }, 99 | "extsprintf": { 100 | "version": "1.3.0", 101 | "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", 102 | "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" 103 | }, 104 | "fast-deep-equal": { 105 | "version": "3.1.1", 106 | "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz", 107 | "integrity": "sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==" 108 | }, 109 | "fast-json-stable-stringify": { 110 | "version": "2.1.0", 111 | "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", 112 | "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==" 113 | }, 114 | "forever-agent": { 115 | "version": "0.6.1", 116 | "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", 117 | "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=" 118 | }, 119 | "form-data": { 120 | "version": "2.3.3", 121 | "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", 122 | "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", 123 | "requires": { 124 | "asynckit": "^0.4.0", 125 | "combined-stream": "^1.0.6", 126 | "mime-types": "^2.1.12" 127 | } 128 | }, 129 | "getpass": { 130 | "version": "0.1.7", 131 | "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", 132 | "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", 133 | "requires": { 134 | "assert-plus": "^1.0.0" 135 | } 136 | }, 137 | "har-schema": { 138 | "version": "2.0.0", 139 | "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", 140 | "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=" 141 | }, 142 | "har-validator": { 143 | "version": "5.1.3", 144 | "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.3.tgz", 145 | "integrity": "sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g==", 146 | "requires": { 147 | "ajv": "^6.5.5", 148 | "har-schema": "^2.0.0" 149 | } 150 | }, 151 | "http-signature": { 152 | "version": "1.2.0", 153 | "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", 154 | "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", 155 | "requires": { 156 | "assert-plus": "^1.0.0", 157 | "jsprim": "^1.2.2", 158 | "sshpk": "^1.7.0" 159 | } 160 | }, 161 | "is-typedarray": { 162 | "version": "1.0.0", 163 | "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", 164 | "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" 165 | }, 166 | "isstream": { 167 | "version": "0.1.2", 168 | "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", 169 | "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" 170 | }, 171 | "jsbn": { 172 | "version": "0.1.1", 173 | "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", 174 | "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" 175 | }, 176 | "json-schema": { 177 | "version": "0.2.3", 178 | "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", 179 | "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" 180 | }, 181 | "json-schema-traverse": { 182 | "version": "0.4.1", 183 | "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", 184 | "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" 185 | }, 186 | "json-stringify-safe": { 187 | "version": "5.0.1", 188 | "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", 189 | "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" 190 | }, 191 | "jsprim": { 192 | "version": "1.4.1", 193 | "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", 194 | "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", 195 | "requires": { 196 | "assert-plus": "1.0.0", 197 | "extsprintf": "1.3.0", 198 | "json-schema": "0.2.3", 199 | "verror": "1.10.0" 200 | } 201 | }, 202 | "mime-db": { 203 | "version": "1.43.0", 204 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.43.0.tgz", 205 | "integrity": "sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ==" 206 | }, 207 | "mime-types": { 208 | "version": "2.1.26", 209 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.26.tgz", 210 | "integrity": "sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==", 211 | "requires": { 212 | "mime-db": "1.43.0" 213 | } 214 | }, 215 | "oauth-sign": { 216 | "version": "0.9.0", 217 | "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", 218 | "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==" 219 | }, 220 | "performance-now": { 221 | "version": "2.1.0", 222 | "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", 223 | "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" 224 | }, 225 | "psl": { 226 | "version": "1.7.0", 227 | "resolved": "https://registry.npmjs.org/psl/-/psl-1.7.0.tgz", 228 | "integrity": "sha512-5NsSEDv8zY70ScRnOTn7bK7eanl2MvFrOrS/R6x+dBt5g1ghnj9Zv90kO8GwT8gxcu2ANyFprnFYB85IogIJOQ==" 229 | }, 230 | "punycode": { 231 | "version": "2.1.1", 232 | "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", 233 | "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" 234 | }, 235 | "qs": { 236 | "version": "6.5.2", 237 | "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", 238 | "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" 239 | }, 240 | "request": { 241 | "version": "2.88.0", 242 | "resolved": "https://registry.npmjs.org/request/-/request-2.88.0.tgz", 243 | "integrity": "sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==", 244 | "requires": { 245 | "aws-sign2": "~0.7.0", 246 | "aws4": "^1.8.0", 247 | "caseless": "~0.12.0", 248 | "combined-stream": "~1.0.6", 249 | "extend": "~3.0.2", 250 | "forever-agent": "~0.6.1", 251 | "form-data": "~2.3.2", 252 | "har-validator": "~5.1.0", 253 | "http-signature": "~1.2.0", 254 | "is-typedarray": "~1.0.0", 255 | "isstream": "~0.1.2", 256 | "json-stringify-safe": "~5.0.1", 257 | "mime-types": "~2.1.19", 258 | "oauth-sign": "~0.9.0", 259 | "performance-now": "^2.1.0", 260 | "qs": "~6.5.2", 261 | "safe-buffer": "^5.1.2", 262 | "tough-cookie": "~2.4.3", 263 | "tunnel-agent": "^0.6.0", 264 | "uuid": "^3.3.2" 265 | } 266 | }, 267 | "safe-buffer": { 268 | "version": "5.2.0", 269 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", 270 | "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==" 271 | }, 272 | "safer-buffer": { 273 | "version": "2.1.2", 274 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 275 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" 276 | }, 277 | "sshpk": { 278 | "version": "1.16.1", 279 | "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", 280 | "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==", 281 | "requires": { 282 | "asn1": "~0.2.3", 283 | "assert-plus": "^1.0.0", 284 | "bcrypt-pbkdf": "^1.0.0", 285 | "dashdash": "^1.12.0", 286 | "ecc-jsbn": "~0.1.1", 287 | "getpass": "^0.1.1", 288 | "jsbn": "~0.1.0", 289 | "safer-buffer": "^2.0.2", 290 | "tweetnacl": "~0.14.0" 291 | } 292 | }, 293 | "tough-cookie": { 294 | "version": "2.4.3", 295 | "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", 296 | "integrity": "sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ==", 297 | "requires": { 298 | "psl": "^1.1.24", 299 | "punycode": "^1.4.1" 300 | }, 301 | "dependencies": { 302 | "punycode": { 303 | "version": "1.4.1", 304 | "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", 305 | "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" 306 | } 307 | } 308 | }, 309 | "tunnel-agent": { 310 | "version": "0.6.0", 311 | "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", 312 | "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", 313 | "requires": { 314 | "safe-buffer": "^5.0.1" 315 | } 316 | }, 317 | "tweetnacl": { 318 | "version": "0.14.5", 319 | "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", 320 | "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" 321 | }, 322 | "uri-js": { 323 | "version": "4.2.2", 324 | "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", 325 | "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", 326 | "requires": { 327 | "punycode": "^2.1.0" 328 | } 329 | }, 330 | "uuid": { 331 | "version": "3.4.0", 332 | "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", 333 | "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==" 334 | }, 335 | "verror": { 336 | "version": "1.10.0", 337 | "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", 338 | "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", 339 | "requires": { 340 | "assert-plus": "^1.0.0", 341 | "core-util-is": "1.0.2", 342 | "extsprintf": "^1.2.0" 343 | } 344 | } 345 | } 346 | } 347 | -------------------------------------------------------------------------------- /Lecture11/node-import/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-import", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "request": "^2.88.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lecture11/node-import/try-request.js: -------------------------------------------------------------------------------- 1 | const request = require('request') 2 | const fs = require('fs') 3 | 4 | request({ 5 | url: 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png', 6 | encoding: null 7 | }, (err, resp, body) => { 8 | if (err) { 9 | console.error(err) 10 | return 11 | } 12 | 13 | console.log(body) 14 | 15 | fs.writeFile('google-logo.png', body, (err) => { 16 | if (err) { 17 | console.error(err) 18 | return 19 | } 20 | console.log('File saved') 21 | }) 22 | }) 23 | -------------------------------------------------------------------------------- /Lecture11/sort-with-promises/Fluent_API.pseudocode: -------------------------------------------------------------------------------- 1 | class Person { 2 | int age 3 | string name 4 | 5 | function setAge(age) { 6 | this.age = age 7 | return this 8 | } 9 | 10 | function setName(name) { 11 | this.name = name 12 | return this 13 | } 14 | } 15 | 16 | Person: p 17 | 18 | new Person().setAge(20).setName('John') 19 | -------------------------------------------------------------------------------- /Lecture11/sort-with-promises/input1.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 22 3 | 3 4 | 44 5 | 545 6 | 656 7 | 4232 8 | 5454 9 | 23 10 | 32 11 | 3244 12 | 535 13 | 342 14 | 435 15 | 34 16 | 2324 17 | 13 18 | 44 19 | 323 20 | 3243 21 | 43 22 | 321 -------------------------------------------------------------------------------- /Lecture11/sort-with-promises/input2.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 4 3 | 545 4 | 56454 5 | 5 6 | 7 7 | 3 8 | 2 9 | 3 10 | 223 11 | 445 12 | 664 13 | 232 14 | 56567 15 | 4534 16 | 8799 17 | 5644 18 | 2122 19 | 32132435 20 | 1224 -------------------------------------------------------------------------------- /Lecture11/sort-with-promises/input3.txt: -------------------------------------------------------------------------------- 1 | 43 2 | 3 3 | 575 4 | 998 5 | 76 6 | 353423 7 | 221 8 | 235 9 | 76543 10 | 12346 11 | 6543 12 | 45 13 | 54 14 | 34 15 | 654 16 | 345 17 | 543 18 | 23456 19 | 5432345 -------------------------------------------------------------------------------- /Lecture11/sort-with-promises/output.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 3 5 | 3 6 | 3 7 | 4 8 | 5 9 | 5 10 | 7 11 | 13 12 | 22 13 | 23 14 | 32 15 | 34 16 | 34 17 | 43 18 | 43 19 | 44 20 | 44 21 | 45 22 | 54 23 | 76 24 | 221 25 | 223 26 | 232 27 | 235 28 | 321 29 | 323 30 | 342 31 | 345 32 | 435 33 | 445 34 | 535 35 | 543 36 | 545 37 | 545 38 | 575 39 | 654 40 | 656 41 | 664 42 | 998 43 | 1224 44 | 2122 45 | 2324 46 | 3243 47 | 3244 48 | 4232 49 | 4534 50 | 5454 51 | 5644 52 | 6543 53 | 8799 54 | 12346 55 | 23456 56 | 56454 57 | 56567 58 | 76543 59 | 353423 60 | 5432345 61 | 32132435 -------------------------------------------------------------------------------- /Lecture11/sort-with-promises/output2.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 3 5 | 3 6 | 3 7 | 4 8 | 5 9 | 5 10 | 7 11 | 13 12 | 22 13 | 23 14 | 32 15 | 34 16 | 34 17 | 43 18 | 43 19 | 44 20 | 44 21 | 45 22 | 54 23 | 76 24 | 221 25 | 223 26 | 232 27 | 235 28 | 321 29 | 323 30 | 342 31 | 345 32 | 435 33 | 445 34 | 535 35 | 543 36 | 545 37 | 545 38 | 575 39 | 654 40 | 656 41 | 664 42 | 998 43 | 1224 44 | 2122 45 | 2324 46 | 3243 47 | 3244 48 | 4232 49 | 4534 50 | 5454 51 | 5644 52 | 6543 53 | 8799 54 | 12346 55 | 23456 56 | 56454 57 | 56567 58 | 76543 59 | 353423 60 | 5432345 61 | 32132435 -------------------------------------------------------------------------------- /Lecture11/sort-with-promises/sort-async-await.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs').promises 2 | const os = require('os') 3 | 4 | async function task() { 5 | try { 6 | console.log('read started') 7 | let p1 = fs.readFile('./input1.txt') 8 | let p2 = fs.readFile('./input2.txt') 9 | let p3 = fs.readFile('./input3.txt') 10 | 11 | let data1 = await p1 12 | console.log('data 1 read') 13 | let data2 = await p2 14 | console.log('data 2 read') 15 | let data3 = await p3 16 | console.log('data 3 read') 17 | 18 | let sorted = data1.toString().split(os.EOL) 19 | .concat(data2.toString().split(os.EOL)) 20 | .concat(data3.toString().split(os.EOL)) 21 | .sort((a, b) => a - b) 22 | .join(os.EOL) 23 | 24 | await fs.writeFile('./output2.txt', sorted) 25 | } catch (e) { 26 | console.error(e) 27 | } 28 | } 29 | 30 | task().then(() => { 31 | console.log('task really done') 32 | }) 33 | 34 | setInterval(() => { 35 | console.log('tick') 36 | }, 1) 37 | -------------------------------------------------------------------------------- /Lecture11/sort-with-promises/sort-promise-how.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | 3 | function readFile(fileName) { 4 | return new Promise((resolve, reject) => { 5 | 6 | fs.readFile(fileName, (err, data) => { 7 | 8 | if(err) { 9 | reject(err) 10 | return 11 | } 12 | 13 | resolve(data) 14 | 15 | }) 16 | 17 | }) 18 | } 19 | 20 | let x = readFile('./input10.txt') 21 | console.log(x) 22 | 23 | x.then((data) => { 24 | console.log(x) 25 | console.log(data) 26 | }) 27 | 28 | x.catch((err) => { 29 | console.log(x) 30 | console.error(err) 31 | }) 32 | -------------------------------------------------------------------------------- /Lecture11/sort-with-promises/sort-promise.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs').promises 2 | const os = require('os') 3 | 4 | fs.readFile('./input1.txt') 5 | .then((data1) => { 6 | fs.readFile('./input2.txt') 7 | .then((data2) => { 8 | fs.readFile('./input3.txt') 9 | .then((data3) => { 10 | 11 | let sorted = data1.toString().split(os.EOL) 12 | .concat(data2.toString().split(os.EOL)) 13 | .concat(data3.toString().split(os.EOL)) 14 | .sort((a,b) => a - b) 15 | .join(os.EOL) 16 | 17 | fs.writeFile('./output.txt', sorted) 18 | .then(() => { 19 | console.log('sorting done') 20 | }) 21 | 22 | }) 23 | }) 24 | }) 25 | -------------------------------------------------------------------------------- /Lecture12/.idea/Lecture12.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lecture12/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /Lecture12/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lecture12/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Lecture12/intro-express/google-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-blocks-archives/Webdev_Pitampura_2019_December/79d23ff5c1d9685bb215e1a58bdd1255461d52fd/Lecture12/intro-express/google-logo.png -------------------------------------------------------------------------------- /Lecture12/intro-express/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "intro-express", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.17.1", 13 | "request": "^2.88.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lecture12/intro-express/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const request = require('request') 3 | const app = express() 4 | 5 | app.get('/', (req, res) => { 6 | res.send(` 7 | 8 | 9 | 14 | 15 | 16 |

    Hello

    17 |

    Welcome to my server

    18 | 19 | 20 | 21 | `) 22 | }) 23 | 24 | app.get('/x', (req, res) => { 25 | res.send("Welcome to my server!") 26 | }) 27 | 28 | app.get('/logo', (req, res) => { 29 | res.sendFile(__dirname + '/google-logo.png') 30 | }) 31 | 32 | app.get('/google', (req, res) => { 33 | res.redirect('https://www.google.com') 34 | }) 35 | 36 | app.get('/example', (req, res) => { 37 | 38 | request('http://example.com', (err, resp, body) => { 39 | res.send(body) 40 | }) 41 | 42 | }) 43 | 44 | app.get('/greet/:name/:greeting', (req, res) => { 45 | console.log(req.params) 46 | let greeting = req.params.greeting 47 | res.send(` Good ${greeting} ${req.params.name}`) 48 | }) 49 | 50 | // http://localhost:3333/greet?name=Jane&greeting=Hi 51 | app.get('/greet', (req, res) => { 52 | console.log(req.query) 53 | let name = 'Guest' 54 | if (req.query.name) { name = req.query.name } 55 | let greeting = 'Hello' 56 | if (req.query.greeting) { greeting = req.query.greeting } 57 | 58 | res.send(`${greeting} ${name}`) 59 | }) 60 | 61 | 62 | app.listen(3333, () => { 63 | console.log('server started') 64 | }) 65 | 66 | app.listen(3334, () => { 67 | console.log('server started') 68 | }) 69 | -------------------------------------------------------------------------------- /Lecture12/intro-express/todolist.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const app = express() 3 | 4 | let todos = [] 5 | 6 | app.get('/', (req, res) => { 7 | 8 | let items = '' 9 | for (let i = 0; i < todos.length; i++) { 10 | items += `
  • ${todos[i]}
  • \n` 11 | } 12 | 13 | 14 | res.send(` 15 |
    16 | 17 | 18 |
    19 |
    20 |
      21 | ${items} 22 |
    23 | `) 24 | }) 25 | 26 | app.get('/add', (req, res) => { 27 | if (req.query.task) { 28 | todos.push(req.query.task) 29 | res.redirect('/') 30 | } else { 31 | res.send('Error: No task defined') 32 | } 33 | }) 34 | 35 | app.get('/:id', (req, res) => { 36 | if (isNaN(parseInt(req.params.id))) { 37 | res.send('Error: id not numerical') 38 | } else { 39 | res.send(todos[req.params.id]) 40 | } 41 | }) 42 | 43 | app.get('/:id/delete', (req, res) => { 44 | if (isNaN(parseInt(req.params.id))) { 45 | res.send('Error: id not numerical') 46 | } else { 47 | if (todos[req.params.id]) { 48 | todos.splice(req.params.id, 1) 49 | res.redirect('/') 50 | } else { 51 | res.send('Error: No task on this index') 52 | } 53 | } 54 | }) 55 | 56 | 57 | 58 | app.listen(4444, () => { 59 | console.log('Started') 60 | }) 61 | -------------------------------------------------------------------------------- /Lecture13/ajax-todo/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ajax-todo", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "accepts": { 8 | "version": "1.3.7", 9 | "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", 10 | "integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==", 11 | "requires": { 12 | "mime-types": "~2.1.24", 13 | "negotiator": "0.6.2" 14 | } 15 | }, 16 | "array-flatten": { 17 | "version": "1.1.1", 18 | "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", 19 | "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" 20 | }, 21 | "body-parser": { 22 | "version": "1.19.0", 23 | "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", 24 | "integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==", 25 | "requires": { 26 | "bytes": "3.1.0", 27 | "content-type": "~1.0.4", 28 | "debug": "2.6.9", 29 | "depd": "~1.1.2", 30 | "http-errors": "1.7.2", 31 | "iconv-lite": "0.4.24", 32 | "on-finished": "~2.3.0", 33 | "qs": "6.7.0", 34 | "raw-body": "2.4.0", 35 | "type-is": "~1.6.17" 36 | } 37 | }, 38 | "bytes": { 39 | "version": "3.1.0", 40 | "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", 41 | "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==" 42 | }, 43 | "content-disposition": { 44 | "version": "0.5.3", 45 | "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz", 46 | "integrity": "sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==", 47 | "requires": { 48 | "safe-buffer": "5.1.2" 49 | } 50 | }, 51 | "content-type": { 52 | "version": "1.0.4", 53 | "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", 54 | "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" 55 | }, 56 | "cookie": { 57 | "version": "0.4.0", 58 | "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz", 59 | "integrity": "sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg==" 60 | }, 61 | "cookie-signature": { 62 | "version": "1.0.6", 63 | "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", 64 | "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" 65 | }, 66 | "debug": { 67 | "version": "2.6.9", 68 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", 69 | "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", 70 | "requires": { 71 | "ms": "2.0.0" 72 | } 73 | }, 74 | "depd": { 75 | "version": "1.1.2", 76 | "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", 77 | "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" 78 | }, 79 | "destroy": { 80 | "version": "1.0.4", 81 | "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", 82 | "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" 83 | }, 84 | "ee-first": { 85 | "version": "1.1.1", 86 | "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", 87 | "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" 88 | }, 89 | "encodeurl": { 90 | "version": "1.0.2", 91 | "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", 92 | "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" 93 | }, 94 | "escape-html": { 95 | "version": "1.0.3", 96 | "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", 97 | "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" 98 | }, 99 | "etag": { 100 | "version": "1.8.1", 101 | "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", 102 | "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" 103 | }, 104 | "express": { 105 | "version": "4.17.1", 106 | "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", 107 | "integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==", 108 | "requires": { 109 | "accepts": "~1.3.7", 110 | "array-flatten": "1.1.1", 111 | "body-parser": "1.19.0", 112 | "content-disposition": "0.5.3", 113 | "content-type": "~1.0.4", 114 | "cookie": "0.4.0", 115 | "cookie-signature": "1.0.6", 116 | "debug": "2.6.9", 117 | "depd": "~1.1.2", 118 | "encodeurl": "~1.0.2", 119 | "escape-html": "~1.0.3", 120 | "etag": "~1.8.1", 121 | "finalhandler": "~1.1.2", 122 | "fresh": "0.5.2", 123 | "merge-descriptors": "1.0.1", 124 | "methods": "~1.1.2", 125 | "on-finished": "~2.3.0", 126 | "parseurl": "~1.3.3", 127 | "path-to-regexp": "0.1.7", 128 | "proxy-addr": "~2.0.5", 129 | "qs": "6.7.0", 130 | "range-parser": "~1.2.1", 131 | "safe-buffer": "5.1.2", 132 | "send": "0.17.1", 133 | "serve-static": "1.14.1", 134 | "setprototypeof": "1.1.1", 135 | "statuses": "~1.5.0", 136 | "type-is": "~1.6.18", 137 | "utils-merge": "1.0.1", 138 | "vary": "~1.1.2" 139 | } 140 | }, 141 | "finalhandler": { 142 | "version": "1.1.2", 143 | "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", 144 | "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", 145 | "requires": { 146 | "debug": "2.6.9", 147 | "encodeurl": "~1.0.2", 148 | "escape-html": "~1.0.3", 149 | "on-finished": "~2.3.0", 150 | "parseurl": "~1.3.3", 151 | "statuses": "~1.5.0", 152 | "unpipe": "~1.0.0" 153 | } 154 | }, 155 | "forwarded": { 156 | "version": "0.1.2", 157 | "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", 158 | "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" 159 | }, 160 | "fresh": { 161 | "version": "0.5.2", 162 | "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", 163 | "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" 164 | }, 165 | "http-errors": { 166 | "version": "1.7.2", 167 | "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz", 168 | "integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==", 169 | "requires": { 170 | "depd": "~1.1.2", 171 | "inherits": "2.0.3", 172 | "setprototypeof": "1.1.1", 173 | "statuses": ">= 1.5.0 < 2", 174 | "toidentifier": "1.0.0" 175 | } 176 | }, 177 | "iconv-lite": { 178 | "version": "0.4.24", 179 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", 180 | "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", 181 | "requires": { 182 | "safer-buffer": ">= 2.1.2 < 3" 183 | } 184 | }, 185 | "inherits": { 186 | "version": "2.0.3", 187 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 188 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" 189 | }, 190 | "ipaddr.js": { 191 | "version": "1.9.0", 192 | "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.0.tgz", 193 | "integrity": "sha512-M4Sjn6N/+O6/IXSJseKqHoFc+5FdGJ22sXqnjTpdZweHK64MzEPAyQZyEU3R/KRv2GLoa7nNtg/C2Ev6m7z+eA==" 194 | }, 195 | "media-typer": { 196 | "version": "0.3.0", 197 | "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", 198 | "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" 199 | }, 200 | "merge-descriptors": { 201 | "version": "1.0.1", 202 | "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", 203 | "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" 204 | }, 205 | "methods": { 206 | "version": "1.1.2", 207 | "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", 208 | "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" 209 | }, 210 | "mime": { 211 | "version": "1.6.0", 212 | "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", 213 | "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==" 214 | }, 215 | "mime-db": { 216 | "version": "1.43.0", 217 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.43.0.tgz", 218 | "integrity": "sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ==" 219 | }, 220 | "mime-types": { 221 | "version": "2.1.26", 222 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.26.tgz", 223 | "integrity": "sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==", 224 | "requires": { 225 | "mime-db": "1.43.0" 226 | } 227 | }, 228 | "ms": { 229 | "version": "2.0.0", 230 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 231 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" 232 | }, 233 | "negotiator": { 234 | "version": "0.6.2", 235 | "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", 236 | "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" 237 | }, 238 | "on-finished": { 239 | "version": "2.3.0", 240 | "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", 241 | "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", 242 | "requires": { 243 | "ee-first": "1.1.1" 244 | } 245 | }, 246 | "parseurl": { 247 | "version": "1.3.3", 248 | "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", 249 | "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" 250 | }, 251 | "path-to-regexp": { 252 | "version": "0.1.7", 253 | "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", 254 | "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" 255 | }, 256 | "proxy-addr": { 257 | "version": "2.0.5", 258 | "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz", 259 | "integrity": "sha512-t/7RxHXPH6cJtP0pRG6smSr9QJidhB+3kXu0KgXnbGYMgzEnUxRQ4/LDdfOwZEMyIh3/xHb8PX3t+lfL9z+YVQ==", 260 | "requires": { 261 | "forwarded": "~0.1.2", 262 | "ipaddr.js": "1.9.0" 263 | } 264 | }, 265 | "qs": { 266 | "version": "6.7.0", 267 | "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", 268 | "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==" 269 | }, 270 | "range-parser": { 271 | "version": "1.2.1", 272 | "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", 273 | "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==" 274 | }, 275 | "raw-body": { 276 | "version": "2.4.0", 277 | "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.0.tgz", 278 | "integrity": "sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q==", 279 | "requires": { 280 | "bytes": "3.1.0", 281 | "http-errors": "1.7.2", 282 | "iconv-lite": "0.4.24", 283 | "unpipe": "1.0.0" 284 | } 285 | }, 286 | "safe-buffer": { 287 | "version": "5.1.2", 288 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 289 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 290 | }, 291 | "safer-buffer": { 292 | "version": "2.1.2", 293 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 294 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" 295 | }, 296 | "send": { 297 | "version": "0.17.1", 298 | "resolved": "https://registry.npmjs.org/send/-/send-0.17.1.tgz", 299 | "integrity": "sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg==", 300 | "requires": { 301 | "debug": "2.6.9", 302 | "depd": "~1.1.2", 303 | "destroy": "~1.0.4", 304 | "encodeurl": "~1.0.2", 305 | "escape-html": "~1.0.3", 306 | "etag": "~1.8.1", 307 | "fresh": "0.5.2", 308 | "http-errors": "~1.7.2", 309 | "mime": "1.6.0", 310 | "ms": "2.1.1", 311 | "on-finished": "~2.3.0", 312 | "range-parser": "~1.2.1", 313 | "statuses": "~1.5.0" 314 | }, 315 | "dependencies": { 316 | "ms": { 317 | "version": "2.1.1", 318 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", 319 | "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" 320 | } 321 | } 322 | }, 323 | "serve-static": { 324 | "version": "1.14.1", 325 | "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.1.tgz", 326 | "integrity": "sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg==", 327 | "requires": { 328 | "encodeurl": "~1.0.2", 329 | "escape-html": "~1.0.3", 330 | "parseurl": "~1.3.3", 331 | "send": "0.17.1" 332 | } 333 | }, 334 | "setprototypeof": { 335 | "version": "1.1.1", 336 | "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", 337 | "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" 338 | }, 339 | "statuses": { 340 | "version": "1.5.0", 341 | "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", 342 | "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" 343 | }, 344 | "toidentifier": { 345 | "version": "1.0.0", 346 | "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", 347 | "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==" 348 | }, 349 | "type-is": { 350 | "version": "1.6.18", 351 | "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", 352 | "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", 353 | "requires": { 354 | "media-typer": "0.3.0", 355 | "mime-types": "~2.1.24" 356 | } 357 | }, 358 | "unpipe": { 359 | "version": "1.0.0", 360 | "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", 361 | "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" 362 | }, 363 | "utils-merge": { 364 | "version": "1.0.1", 365 | "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", 366 | "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" 367 | }, 368 | "vary": { 369 | "version": "1.1.2", 370 | "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", 371 | "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" 372 | } 373 | } 374 | } 375 | -------------------------------------------------------------------------------- /Lecture13/ajax-todo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ajax-todo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "server.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "node server.js" 9 | }, 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "express": "^4.17.1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lecture13/ajax-todo/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 | 10 | 11 | Go to Google 12 |
    13 | 14 | 15 | 16 | 17 | 20 | 21 | -------------------------------------------------------------------------------- /Lecture13/ajax-todo/public/script-classic.js: -------------------------------------------------------------------------------- 1 | window.onload = function () { 2 | let btnLoad = document.getElementById('load') 3 | btnLoad.onclick = function () { 4 | let req = new XMLHttpRequest(); 5 | req.addEventListener('load', (event) => { 6 | console.log(JSON.parse(req.response)) 7 | }) 8 | req.open('GET', '/todos') 9 | req.send() 10 | } 11 | } -------------------------------------------------------------------------------- /Lecture13/ajax-todo/public/script.js: -------------------------------------------------------------------------------- 1 | $(() => { 2 | function showData(data) { 3 | $("#todos").empty(); 4 | for (let task of data) { 5 | $("#todos").append($("
  • ").text(task)); 6 | } 7 | } 8 | 9 | $("#load").click(() => { 10 | $.get("/todos", data => { 11 | showData(data) 12 | }); 13 | }); 14 | 15 | $("#add").click(() => { 16 | let newtask = $("#newtask").val(); 17 | $.get("/todos/add?task=" + newtask, data => { 18 | showData(data) 19 | }); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /Lecture13/ajax-todo/public/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-blocks-archives/Webdev_Pitampura_2019_December/79d23ff5c1d9685bb215e1a58bdd1255461d52fd/Lecture13/ajax-todo/public/style.css -------------------------------------------------------------------------------- /Lecture13/ajax-todo/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const app = express() 3 | 4 | let todos = [ 5 | 'some tasks', 6 | 'more tasks', 7 | 'another sample task' 8 | ] 9 | 10 | app.use('/', express.static(__dirname + '/public')) 11 | 12 | app.get('/todos', (req, res) => { 13 | res.send(todos) 14 | }) 15 | 16 | app.get('/todos/add', (req, res) => { 17 | todos.push(req.query.task) 18 | res.send(todos) 19 | }) 20 | 21 | 22 | app.listen(3456, () => { 23 | console.log('started on http://localhost:3456') 24 | }) -------------------------------------------------------------------------------- /Lecture13/ajax-with-express/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml 3 | -------------------------------------------------------------------------------- /Lecture13/ajax-with-express/.idea/ajax-with-express.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lecture13/ajax-with-express/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /Lecture13/ajax-with-express/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lecture13/ajax-with-express/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Lecture13/ajax-with-express/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ajax-with-express", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "accepts": { 8 | "version": "1.3.7", 9 | "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", 10 | "integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==", 11 | "requires": { 12 | "mime-types": "~2.1.24", 13 | "negotiator": "0.6.2" 14 | } 15 | }, 16 | "array-flatten": { 17 | "version": "1.1.1", 18 | "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", 19 | "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" 20 | }, 21 | "body-parser": { 22 | "version": "1.19.0", 23 | "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", 24 | "integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==", 25 | "requires": { 26 | "bytes": "3.1.0", 27 | "content-type": "~1.0.4", 28 | "debug": "2.6.9", 29 | "depd": "~1.1.2", 30 | "http-errors": "1.7.2", 31 | "iconv-lite": "0.4.24", 32 | "on-finished": "~2.3.0", 33 | "qs": "6.7.0", 34 | "raw-body": "2.4.0", 35 | "type-is": "~1.6.17" 36 | } 37 | }, 38 | "bytes": { 39 | "version": "3.1.0", 40 | "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", 41 | "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==" 42 | }, 43 | "content-disposition": { 44 | "version": "0.5.3", 45 | "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz", 46 | "integrity": "sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==", 47 | "requires": { 48 | "safe-buffer": "5.1.2" 49 | } 50 | }, 51 | "content-type": { 52 | "version": "1.0.4", 53 | "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", 54 | "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" 55 | }, 56 | "cookie": { 57 | "version": "0.4.0", 58 | "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz", 59 | "integrity": "sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg==" 60 | }, 61 | "cookie-signature": { 62 | "version": "1.0.6", 63 | "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", 64 | "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" 65 | }, 66 | "debug": { 67 | "version": "2.6.9", 68 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", 69 | "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", 70 | "requires": { 71 | "ms": "2.0.0" 72 | } 73 | }, 74 | "depd": { 75 | "version": "1.1.2", 76 | "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", 77 | "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" 78 | }, 79 | "destroy": { 80 | "version": "1.0.4", 81 | "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", 82 | "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" 83 | }, 84 | "ee-first": { 85 | "version": "1.1.1", 86 | "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", 87 | "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" 88 | }, 89 | "encodeurl": { 90 | "version": "1.0.2", 91 | "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", 92 | "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" 93 | }, 94 | "escape-html": { 95 | "version": "1.0.3", 96 | "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", 97 | "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" 98 | }, 99 | "etag": { 100 | "version": "1.8.1", 101 | "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", 102 | "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" 103 | }, 104 | "express": { 105 | "version": "4.17.1", 106 | "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", 107 | "integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==", 108 | "requires": { 109 | "accepts": "~1.3.7", 110 | "array-flatten": "1.1.1", 111 | "body-parser": "1.19.0", 112 | "content-disposition": "0.5.3", 113 | "content-type": "~1.0.4", 114 | "cookie": "0.4.0", 115 | "cookie-signature": "1.0.6", 116 | "debug": "2.6.9", 117 | "depd": "~1.1.2", 118 | "encodeurl": "~1.0.2", 119 | "escape-html": "~1.0.3", 120 | "etag": "~1.8.1", 121 | "finalhandler": "~1.1.2", 122 | "fresh": "0.5.2", 123 | "merge-descriptors": "1.0.1", 124 | "methods": "~1.1.2", 125 | "on-finished": "~2.3.0", 126 | "parseurl": "~1.3.3", 127 | "path-to-regexp": "0.1.7", 128 | "proxy-addr": "~2.0.5", 129 | "qs": "6.7.0", 130 | "range-parser": "~1.2.1", 131 | "safe-buffer": "5.1.2", 132 | "send": "0.17.1", 133 | "serve-static": "1.14.1", 134 | "setprototypeof": "1.1.1", 135 | "statuses": "~1.5.0", 136 | "type-is": "~1.6.18", 137 | "utils-merge": "1.0.1", 138 | "vary": "~1.1.2" 139 | } 140 | }, 141 | "finalhandler": { 142 | "version": "1.1.2", 143 | "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", 144 | "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", 145 | "requires": { 146 | "debug": "2.6.9", 147 | "encodeurl": "~1.0.2", 148 | "escape-html": "~1.0.3", 149 | "on-finished": "~2.3.0", 150 | "parseurl": "~1.3.3", 151 | "statuses": "~1.5.0", 152 | "unpipe": "~1.0.0" 153 | } 154 | }, 155 | "forwarded": { 156 | "version": "0.1.2", 157 | "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", 158 | "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" 159 | }, 160 | "fresh": { 161 | "version": "0.5.2", 162 | "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", 163 | "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" 164 | }, 165 | "http-errors": { 166 | "version": "1.7.2", 167 | "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz", 168 | "integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==", 169 | "requires": { 170 | "depd": "~1.1.2", 171 | "inherits": "2.0.3", 172 | "setprototypeof": "1.1.1", 173 | "statuses": ">= 1.5.0 < 2", 174 | "toidentifier": "1.0.0" 175 | } 176 | }, 177 | "iconv-lite": { 178 | "version": "0.4.24", 179 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", 180 | "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", 181 | "requires": { 182 | "safer-buffer": ">= 2.1.2 < 3" 183 | } 184 | }, 185 | "inherits": { 186 | "version": "2.0.3", 187 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 188 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" 189 | }, 190 | "ipaddr.js": { 191 | "version": "1.9.0", 192 | "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.0.tgz", 193 | "integrity": "sha512-M4Sjn6N/+O6/IXSJseKqHoFc+5FdGJ22sXqnjTpdZweHK64MzEPAyQZyEU3R/KRv2GLoa7nNtg/C2Ev6m7z+eA==" 194 | }, 195 | "media-typer": { 196 | "version": "0.3.0", 197 | "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", 198 | "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" 199 | }, 200 | "merge-descriptors": { 201 | "version": "1.0.1", 202 | "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", 203 | "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" 204 | }, 205 | "methods": { 206 | "version": "1.1.2", 207 | "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", 208 | "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" 209 | }, 210 | "mime": { 211 | "version": "1.6.0", 212 | "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", 213 | "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==" 214 | }, 215 | "mime-db": { 216 | "version": "1.43.0", 217 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.43.0.tgz", 218 | "integrity": "sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ==" 219 | }, 220 | "mime-types": { 221 | "version": "2.1.26", 222 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.26.tgz", 223 | "integrity": "sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==", 224 | "requires": { 225 | "mime-db": "1.43.0" 226 | } 227 | }, 228 | "ms": { 229 | "version": "2.0.0", 230 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 231 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" 232 | }, 233 | "negotiator": { 234 | "version": "0.6.2", 235 | "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", 236 | "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" 237 | }, 238 | "on-finished": { 239 | "version": "2.3.0", 240 | "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", 241 | "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", 242 | "requires": { 243 | "ee-first": "1.1.1" 244 | } 245 | }, 246 | "parseurl": { 247 | "version": "1.3.3", 248 | "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", 249 | "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" 250 | }, 251 | "path-to-regexp": { 252 | "version": "0.1.7", 253 | "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", 254 | "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" 255 | }, 256 | "proxy-addr": { 257 | "version": "2.0.5", 258 | "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz", 259 | "integrity": "sha512-t/7RxHXPH6cJtP0pRG6smSr9QJidhB+3kXu0KgXnbGYMgzEnUxRQ4/LDdfOwZEMyIh3/xHb8PX3t+lfL9z+YVQ==", 260 | "requires": { 261 | "forwarded": "~0.1.2", 262 | "ipaddr.js": "1.9.0" 263 | } 264 | }, 265 | "qs": { 266 | "version": "6.7.0", 267 | "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", 268 | "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==" 269 | }, 270 | "range-parser": { 271 | "version": "1.2.1", 272 | "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", 273 | "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==" 274 | }, 275 | "raw-body": { 276 | "version": "2.4.0", 277 | "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.0.tgz", 278 | "integrity": "sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q==", 279 | "requires": { 280 | "bytes": "3.1.0", 281 | "http-errors": "1.7.2", 282 | "iconv-lite": "0.4.24", 283 | "unpipe": "1.0.0" 284 | } 285 | }, 286 | "safe-buffer": { 287 | "version": "5.1.2", 288 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 289 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 290 | }, 291 | "safer-buffer": { 292 | "version": "2.1.2", 293 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 294 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" 295 | }, 296 | "send": { 297 | "version": "0.17.1", 298 | "resolved": "https://registry.npmjs.org/send/-/send-0.17.1.tgz", 299 | "integrity": "sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg==", 300 | "requires": { 301 | "debug": "2.6.9", 302 | "depd": "~1.1.2", 303 | "destroy": "~1.0.4", 304 | "encodeurl": "~1.0.2", 305 | "escape-html": "~1.0.3", 306 | "etag": "~1.8.1", 307 | "fresh": "0.5.2", 308 | "http-errors": "~1.7.2", 309 | "mime": "1.6.0", 310 | "ms": "2.1.1", 311 | "on-finished": "~2.3.0", 312 | "range-parser": "~1.2.1", 313 | "statuses": "~1.5.0" 314 | }, 315 | "dependencies": { 316 | "ms": { 317 | "version": "2.1.1", 318 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", 319 | "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" 320 | } 321 | } 322 | }, 323 | "serve-static": { 324 | "version": "1.14.1", 325 | "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.1.tgz", 326 | "integrity": "sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg==", 327 | "requires": { 328 | "encodeurl": "~1.0.2", 329 | "escape-html": "~1.0.3", 330 | "parseurl": "~1.3.3", 331 | "send": "0.17.1" 332 | } 333 | }, 334 | "setprototypeof": { 335 | "version": "1.1.1", 336 | "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", 337 | "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" 338 | }, 339 | "statuses": { 340 | "version": "1.5.0", 341 | "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", 342 | "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" 343 | }, 344 | "toidentifier": { 345 | "version": "1.0.0", 346 | "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", 347 | "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==" 348 | }, 349 | "type-is": { 350 | "version": "1.6.18", 351 | "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", 352 | "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", 353 | "requires": { 354 | "media-typer": "0.3.0", 355 | "mime-types": "~2.1.24" 356 | } 357 | }, 358 | "unpipe": { 359 | "version": "1.0.0", 360 | "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", 361 | "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" 362 | }, 363 | "utils-merge": { 364 | "version": "1.0.1", 365 | "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", 366 | "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" 367 | }, 368 | "vary": { 369 | "version": "1.1.2", 370 | "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", 371 | "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" 372 | } 373 | } 374 | } 375 | -------------------------------------------------------------------------------- /Lecture13/ajax-with-express/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ajax-with-express", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "server.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "node server.js" 9 | }, 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "express": "^4.17.1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lecture13/ajax-with-express/public/a.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 | 11 |

    This is file a

    12 | 13 | 14 | -------------------------------------------------------------------------------- /Lecture13/ajax-with-express/public/alert.js: -------------------------------------------------------------------------------- 1 | window.onload = function () { 2 | alert('Hello') 3 | } -------------------------------------------------------------------------------- /Lecture13/ajax-with-express/public/b.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 |

    This is file B

    10 | 11 | 12 | -------------------------------------------------------------------------------- /Lecture13/ajax-with-express/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 | 11 |

    Hello World

    12 | 13 | 14 | -------------------------------------------------------------------------------- /Lecture13/ajax-with-express/public/style.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | color: red; 3 | } -------------------------------------------------------------------------------- /Lecture13/ajax-with-express/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | 3 | const app = express() 4 | 5 | app.get('/', (req, res) => { 6 | res.send('Hello World') 7 | }) 8 | 9 | app.use('/abc', express.static('./public')) 10 | 11 | app.listen(5555, () => { 12 | console.log('Server started') 13 | }) -------------------------------------------------------------------------------- /Lecture13/express-middlewares/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "express-middlewares", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "accepts": { 8 | "version": "1.3.7", 9 | "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", 10 | "integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==", 11 | "requires": { 12 | "mime-types": "~2.1.24", 13 | "negotiator": "0.6.2" 14 | } 15 | }, 16 | "array-flatten": { 17 | "version": "1.1.1", 18 | "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", 19 | "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" 20 | }, 21 | "body-parser": { 22 | "version": "1.19.0", 23 | "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", 24 | "integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==", 25 | "requires": { 26 | "bytes": "3.1.0", 27 | "content-type": "~1.0.4", 28 | "debug": "2.6.9", 29 | "depd": "~1.1.2", 30 | "http-errors": "1.7.2", 31 | "iconv-lite": "0.4.24", 32 | "on-finished": "~2.3.0", 33 | "qs": "6.7.0", 34 | "raw-body": "2.4.0", 35 | "type-is": "~1.6.17" 36 | } 37 | }, 38 | "bytes": { 39 | "version": "3.1.0", 40 | "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", 41 | "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==" 42 | }, 43 | "content-disposition": { 44 | "version": "0.5.3", 45 | "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz", 46 | "integrity": "sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==", 47 | "requires": { 48 | "safe-buffer": "5.1.2" 49 | } 50 | }, 51 | "content-type": { 52 | "version": "1.0.4", 53 | "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", 54 | "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" 55 | }, 56 | "cookie": { 57 | "version": "0.4.0", 58 | "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz", 59 | "integrity": "sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg==" 60 | }, 61 | "cookie-signature": { 62 | "version": "1.0.6", 63 | "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", 64 | "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" 65 | }, 66 | "debug": { 67 | "version": "2.6.9", 68 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", 69 | "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", 70 | "requires": { 71 | "ms": "2.0.0" 72 | } 73 | }, 74 | "depd": { 75 | "version": "1.1.2", 76 | "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", 77 | "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" 78 | }, 79 | "destroy": { 80 | "version": "1.0.4", 81 | "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", 82 | "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" 83 | }, 84 | "ee-first": { 85 | "version": "1.1.1", 86 | "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", 87 | "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" 88 | }, 89 | "encodeurl": { 90 | "version": "1.0.2", 91 | "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", 92 | "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" 93 | }, 94 | "escape-html": { 95 | "version": "1.0.3", 96 | "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", 97 | "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" 98 | }, 99 | "etag": { 100 | "version": "1.8.1", 101 | "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", 102 | "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" 103 | }, 104 | "express": { 105 | "version": "4.17.1", 106 | "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", 107 | "integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==", 108 | "requires": { 109 | "accepts": "~1.3.7", 110 | "array-flatten": "1.1.1", 111 | "body-parser": "1.19.0", 112 | "content-disposition": "0.5.3", 113 | "content-type": "~1.0.4", 114 | "cookie": "0.4.0", 115 | "cookie-signature": "1.0.6", 116 | "debug": "2.6.9", 117 | "depd": "~1.1.2", 118 | "encodeurl": "~1.0.2", 119 | "escape-html": "~1.0.3", 120 | "etag": "~1.8.1", 121 | "finalhandler": "~1.1.2", 122 | "fresh": "0.5.2", 123 | "merge-descriptors": "1.0.1", 124 | "methods": "~1.1.2", 125 | "on-finished": "~2.3.0", 126 | "parseurl": "~1.3.3", 127 | "path-to-regexp": "0.1.7", 128 | "proxy-addr": "~2.0.5", 129 | "qs": "6.7.0", 130 | "range-parser": "~1.2.1", 131 | "safe-buffer": "5.1.2", 132 | "send": "0.17.1", 133 | "serve-static": "1.14.1", 134 | "setprototypeof": "1.1.1", 135 | "statuses": "~1.5.0", 136 | "type-is": "~1.6.18", 137 | "utils-merge": "1.0.1", 138 | "vary": "~1.1.2" 139 | } 140 | }, 141 | "finalhandler": { 142 | "version": "1.1.2", 143 | "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", 144 | "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", 145 | "requires": { 146 | "debug": "2.6.9", 147 | "encodeurl": "~1.0.2", 148 | "escape-html": "~1.0.3", 149 | "on-finished": "~2.3.0", 150 | "parseurl": "~1.3.3", 151 | "statuses": "~1.5.0", 152 | "unpipe": "~1.0.0" 153 | } 154 | }, 155 | "forwarded": { 156 | "version": "0.1.2", 157 | "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", 158 | "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" 159 | }, 160 | "fresh": { 161 | "version": "0.5.2", 162 | "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", 163 | "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" 164 | }, 165 | "http-errors": { 166 | "version": "1.7.2", 167 | "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz", 168 | "integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==", 169 | "requires": { 170 | "depd": "~1.1.2", 171 | "inherits": "2.0.3", 172 | "setprototypeof": "1.1.1", 173 | "statuses": ">= 1.5.0 < 2", 174 | "toidentifier": "1.0.0" 175 | } 176 | }, 177 | "iconv-lite": { 178 | "version": "0.4.24", 179 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", 180 | "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", 181 | "requires": { 182 | "safer-buffer": ">= 2.1.2 < 3" 183 | } 184 | }, 185 | "inherits": { 186 | "version": "2.0.3", 187 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 188 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" 189 | }, 190 | "ipaddr.js": { 191 | "version": "1.9.0", 192 | "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.0.tgz", 193 | "integrity": "sha512-M4Sjn6N/+O6/IXSJseKqHoFc+5FdGJ22sXqnjTpdZweHK64MzEPAyQZyEU3R/KRv2GLoa7nNtg/C2Ev6m7z+eA==" 194 | }, 195 | "media-typer": { 196 | "version": "0.3.0", 197 | "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", 198 | "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" 199 | }, 200 | "merge-descriptors": { 201 | "version": "1.0.1", 202 | "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", 203 | "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" 204 | }, 205 | "methods": { 206 | "version": "1.1.2", 207 | "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", 208 | "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" 209 | }, 210 | "mime": { 211 | "version": "1.6.0", 212 | "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", 213 | "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==" 214 | }, 215 | "mime-db": { 216 | "version": "1.43.0", 217 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.43.0.tgz", 218 | "integrity": "sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ==" 219 | }, 220 | "mime-types": { 221 | "version": "2.1.26", 222 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.26.tgz", 223 | "integrity": "sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==", 224 | "requires": { 225 | "mime-db": "1.43.0" 226 | } 227 | }, 228 | "ms": { 229 | "version": "2.0.0", 230 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 231 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" 232 | }, 233 | "negotiator": { 234 | "version": "0.6.2", 235 | "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", 236 | "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" 237 | }, 238 | "on-finished": { 239 | "version": "2.3.0", 240 | "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", 241 | "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", 242 | "requires": { 243 | "ee-first": "1.1.1" 244 | } 245 | }, 246 | "parseurl": { 247 | "version": "1.3.3", 248 | "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", 249 | "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" 250 | }, 251 | "path-to-regexp": { 252 | "version": "0.1.7", 253 | "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", 254 | "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" 255 | }, 256 | "proxy-addr": { 257 | "version": "2.0.5", 258 | "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz", 259 | "integrity": "sha512-t/7RxHXPH6cJtP0pRG6smSr9QJidhB+3kXu0KgXnbGYMgzEnUxRQ4/LDdfOwZEMyIh3/xHb8PX3t+lfL9z+YVQ==", 260 | "requires": { 261 | "forwarded": "~0.1.2", 262 | "ipaddr.js": "1.9.0" 263 | } 264 | }, 265 | "qs": { 266 | "version": "6.7.0", 267 | "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", 268 | "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==" 269 | }, 270 | "range-parser": { 271 | "version": "1.2.1", 272 | "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", 273 | "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==" 274 | }, 275 | "raw-body": { 276 | "version": "2.4.0", 277 | "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.0.tgz", 278 | "integrity": "sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q==", 279 | "requires": { 280 | "bytes": "3.1.0", 281 | "http-errors": "1.7.2", 282 | "iconv-lite": "0.4.24", 283 | "unpipe": "1.0.0" 284 | } 285 | }, 286 | "safe-buffer": { 287 | "version": "5.1.2", 288 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 289 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 290 | }, 291 | "safer-buffer": { 292 | "version": "2.1.2", 293 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 294 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" 295 | }, 296 | "send": { 297 | "version": "0.17.1", 298 | "resolved": "https://registry.npmjs.org/send/-/send-0.17.1.tgz", 299 | "integrity": "sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg==", 300 | "requires": { 301 | "debug": "2.6.9", 302 | "depd": "~1.1.2", 303 | "destroy": "~1.0.4", 304 | "encodeurl": "~1.0.2", 305 | "escape-html": "~1.0.3", 306 | "etag": "~1.8.1", 307 | "fresh": "0.5.2", 308 | "http-errors": "~1.7.2", 309 | "mime": "1.6.0", 310 | "ms": "2.1.1", 311 | "on-finished": "~2.3.0", 312 | "range-parser": "~1.2.1", 313 | "statuses": "~1.5.0" 314 | }, 315 | "dependencies": { 316 | "ms": { 317 | "version": "2.1.1", 318 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", 319 | "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" 320 | } 321 | } 322 | }, 323 | "serve-static": { 324 | "version": "1.14.1", 325 | "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.1.tgz", 326 | "integrity": "sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg==", 327 | "requires": { 328 | "encodeurl": "~1.0.2", 329 | "escape-html": "~1.0.3", 330 | "parseurl": "~1.3.3", 331 | "send": "0.17.1" 332 | } 333 | }, 334 | "setprototypeof": { 335 | "version": "1.1.1", 336 | "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", 337 | "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" 338 | }, 339 | "statuses": { 340 | "version": "1.5.0", 341 | "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", 342 | "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" 343 | }, 344 | "toidentifier": { 345 | "version": "1.0.0", 346 | "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", 347 | "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==" 348 | }, 349 | "type-is": { 350 | "version": "1.6.18", 351 | "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", 352 | "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", 353 | "requires": { 354 | "media-typer": "0.3.0", 355 | "mime-types": "~2.1.24" 356 | } 357 | }, 358 | "unpipe": { 359 | "version": "1.0.0", 360 | "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", 361 | "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" 362 | }, 363 | "utils-merge": { 364 | "version": "1.0.1", 365 | "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", 366 | "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" 367 | }, 368 | "vary": { 369 | "version": "1.1.2", 370 | "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", 371 | "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" 372 | } 373 | } 374 | } 375 | -------------------------------------------------------------------------------- /Lecture13/express-middlewares/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "express-middlewares", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.17.1" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lecture13/express-middlewares/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const app = express() 3 | 4 | function m (req, res, next) { 5 | console.log(req.url) 6 | next() 7 | } 8 | 9 | function m0 (req, res, next) { 10 | console.log(req.url) 11 | console.log('running m0') 12 | if (req.url != '/1' && req.url != '/2') { 13 | 14 | res.send('nothing to see here') 15 | 16 | } else { 17 | next() 18 | } 19 | } 20 | 21 | function m1 (req, res) { 22 | console.log('running m1') 23 | res.send('done') 24 | } 25 | 26 | function m2 (req, res) { 27 | console.log('running m2') 28 | res.send('done') 29 | } 30 | 31 | function m3 (req, res) { 32 | console.log('running m3') 33 | res.send('done') 34 | } 35 | app.use(m) 36 | 37 | app.get('/1', m0, m1) 38 | 39 | app.get('/2', m0, m2) 40 | 41 | app.get('/3', m0, m3) 42 | 43 | app.listen(5656, () => { 44 | console.log('started on localhost:5656') 45 | }) -------------------------------------------------------------------------------- /Lecture13/express-middlewares/server2.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | 3 | const app = express() 4 | 5 | function a(req, res, next) { 6 | console.log('running a') 7 | next() 8 | } 9 | 10 | app.use('/a', a) 11 | 12 | app.get('/a/b', (req, res) => { 13 | res.send('you are on /a/b') 14 | }) 15 | 16 | app.get('/a/c', (req, res) => { 17 | res.send('you are on /a/c') 18 | }) 19 | 20 | 21 | app.listen(4545, () => { 22 | console.log('started on http://localhost:4545') 23 | }) -------------------------------------------------------------------------------- /Lecture13/express-middlewares/server3.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const app = express() 3 | 4 | 5 | function m1 (req, res, next) { 6 | console.log('running m1') 7 | if (req.query.ret == '1') 8 | return res.send('return from m1') 9 | next() 10 | } 11 | function m2 (req, res, next) { 12 | console.log('running m2') 13 | if (req.query.ret == '2') 14 | return res.send('return from m2') 15 | next() 16 | } 17 | function m3 (req, res, next) { 18 | console.log('running m3') 19 | if (req.query.ret == '3') 20 | return res.send('return from m3') 21 | next() 22 | } 23 | function m4 (req, res, next) { 24 | console.log('running m4') 25 | if (req.query.ret == '4') 26 | return res.send('return from m4') 27 | next() 28 | } 29 | function m5 (req, res, next) { 30 | console.log('running m5') 31 | if (req.query.ret == '5') 32 | return res.send('return from m5') 33 | next() 34 | } 35 | function m6 (req, res, next) { 36 | console.log('running m6') 37 | if (req.query.ret == '6') 38 | return res.send('return from m6') 39 | next() 40 | } 41 | function m7 (req, res, next) { 42 | console.log('running m7') 43 | if (req.query.ret == '7') 44 | return res.send('return from m7') 45 | next() 46 | } 47 | 48 | // app.use((req, res, next) => { 49 | // if (req.url == '/favicon.ico') 50 | // res.send(null) 51 | // else 52 | // next() 53 | // }) 54 | 55 | app.use('/a', m1) 56 | app.use('/b', m2) 57 | app.use(m3) 58 | app.use('/a/b', m4) 59 | app.use('/a', m5) 60 | app.use('/a/b/x', m6) 61 | app.use('/a/c', m7) 62 | 63 | /* /a/b/c */ 64 | 65 | 66 | app.listen(4343, () => { 67 | console.log('started on http://localhost:4343') 68 | }) -------------------------------------------------------------------------------- /Lecture13/express-middlewares/server4.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const app = express() 3 | 4 | function decrypt(str) { 5 | 6 | } 7 | 8 | app.use((req, res, next) => { 9 | for (let q in req.query) { 10 | req.query[q] = decrypt(req.query[q]) 11 | } 12 | next() 13 | }) 14 | 15 | app.use((req, res, next) => { 16 | if (!req.query.name) { 17 | req.query.name = 'Guest' 18 | } 19 | next() 20 | }) 21 | 22 | app.get('/hello', (req, res) => { 23 | res.send('Hello ' + req.query.name) 24 | }) 25 | 26 | app.get('/bye', (req, res) => { 27 | res.send('Goodbye ' + req.query.name) 28 | }) 29 | 30 | app.listen(3434, () => { 31 | console.log('started') 32 | }) -------------------------------------------------------------------------------- /Lecture14/hbs-rendering/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hbs-rendering", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.17.1", 13 | "hbs": "^4.1.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lecture14/hbs-rendering/public/todo.js: -------------------------------------------------------------------------------- 1 | $(() => { 2 | 3 | function refreshList(data) { 4 | $('#tasklist').empty() 5 | for (let task of data) { 6 | $('#tasklist').append( 7 | $('
  • ') 8 | .append( 9 | $('') 10 | .attr('checked', task.done) 11 | ) 12 | .append( 13 | $('').text(' - - ' + task.name) 14 | ) 15 | ) 16 | } 17 | } 18 | 19 | $.get('/api/todos', refreshList) 20 | 21 | $('#addtask').click((e) => { 22 | e.preventDefault() 23 | 24 | $.post( 25 | '/api/add', 26 | { 27 | newtask: $('#newtask').val(), 28 | completed: $('#completed').prop('checked') 29 | }, 30 | (data) => { 31 | refreshList(data) 32 | } 33 | ) 34 | }) 35 | }) -------------------------------------------------------------------------------- /Lecture14/hbs-rendering/server.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const app = express(); 3 | 4 | app.set("view engine", "hbs"); 5 | 6 | let todos = [ 7 | { name: "first task", done: false }, 8 | { name: "another task", done: true }, 9 | { name: "third task", done: true }, 10 | { name: "one more task", done: false } 11 | ]; 12 | 13 | app.use((req, res, next) => { 14 | setTimeout(next, 3000); 15 | }); 16 | 17 | // These are middlewares that help parse the req.body 18 | app.use(express.urlencoded({ extended: true })); 19 | app.use(express.json()); 20 | 21 | app.use("/", express.static(__dirname + "/public")); 22 | 23 | app.get("/", (req, res) => { 24 | res.render("todo", { 25 | title: "Todo List", 26 | todos: todos 27 | }); 28 | }); 29 | 30 | app.post("/add", (req, res) => { 31 | console.log("POST /add"); 32 | console.log(req.body); 33 | if (req.body.newtask) { 34 | todos.push({ 35 | name: req.body.newtask, 36 | done: req.body.completed == "on" 37 | }); 38 | } 39 | res.redirect("/"); 40 | }); 41 | 42 | app.get("/api/todos", (req, res) => { 43 | res.send(todos); 44 | }); 45 | 46 | app.post("/api/add", (req, res) => { 47 | console.log("POST /api/add"); 48 | console.log(req.body); 49 | if (req.body.newtask) { 50 | todos.push({ 51 | name: req.body.newtask, 52 | done: req.body.completed == "true" 53 | }); 54 | } 55 | res.send(todos); 56 | }); 57 | 58 | app.listen(5432, () => { 59 | console.log("started on http://localhost:5432"); 60 | }); 61 | -------------------------------------------------------------------------------- /Lecture14/hbs-rendering/views/faq.hbs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-blocks-archives/Webdev_Pitampura_2019_December/79d23ff5c1d9685bb215e1a58bdd1255461d52fd/Lecture14/hbs-rendering/views/faq.hbs -------------------------------------------------------------------------------- /Lecture14/hbs-rendering/views/todo.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {{title}} 7 | 8 | 9 | 10 | 11 |
    12 | 13 | 14 | 15 |
    16 |
      17 | {{#each todos as |todo|}} 18 |
    • 19 | {{#if todo.done}} 20 | 21 | {{else}} 22 | 23 | {{/if}} 24 | 25 | {{todo.name}} 26 |
    • 27 | {{/each}} 28 |
    29 | 30 | -------------------------------------------------------------------------------- /Lecture15/mysql-intro/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ### Login to MySQL (as root) 4 | 5 | ```shell 6 | mysql -u root -p 7 | # or 8 | mysql -u root #without password 9 | #or 10 | sudo mysql #on ubuntu 11 | ``` 12 | ### Create Database and User (inside MySQL) 13 | 14 | ```mysql 15 | CREATE DATABASE mytestdb; 16 | 17 | CREATE USER mytestuser IDENTIFIED WITH mysql_native_password BY 'mytestpass'; 18 | 19 | GRANT ALL PRIVILEGES ON mytestdb.* TO mytestuser; 20 | 21 | FLUSH PRIVILEGES; 22 | 23 | EXIT 24 | ``` 25 | 26 | ### If there is Password policy problems 27 | 28 | ```mysql 29 | SET GLOBAL validate_password_policy=LOW; 30 | ``` 31 | 32 | ### Login to MySQL (as the new user) 33 | 34 | ```shell 35 | mysql -u mytestuser -p 36 | 37 | ``` 38 | 39 | ### Create Table 40 | 41 | ```mysql 42 | CREATE TABLE myfirsttable ( 43 | id INTEGER AUTO_INCREMENT PRIMARY KEY, 44 | name TEXT 45 | ); 46 | ``` 47 | -------------------------------------------------------------------------------- /Lecture15/mysql-intro/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mysql-intro", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "ansicolors": { 8 | "version": "0.3.2", 9 | "resolved": "https://registry.npmjs.org/ansicolors/-/ansicolors-0.3.2.tgz", 10 | "integrity": "sha1-ZlWX3oap/+Oqm/vmyuXG6kJrSXk=" 11 | }, 12 | "cardinal": { 13 | "version": "2.1.1", 14 | "resolved": "https://registry.npmjs.org/cardinal/-/cardinal-2.1.1.tgz", 15 | "integrity": "sha1-fMEFXYItISlU0HsIXeolHMe8VQU=", 16 | "requires": { 17 | "ansicolors": "~0.3.2", 18 | "redeyed": "~2.1.0" 19 | } 20 | }, 21 | "denque": { 22 | "version": "1.4.1", 23 | "resolved": "https://registry.npmjs.org/denque/-/denque-1.4.1.tgz", 24 | "integrity": "sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ==" 25 | }, 26 | "esprima": { 27 | "version": "4.0.1", 28 | "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", 29 | "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" 30 | }, 31 | "generate-function": { 32 | "version": "2.3.1", 33 | "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz", 34 | "integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==", 35 | "requires": { 36 | "is-property": "^1.0.2" 37 | } 38 | }, 39 | "iconv-lite": { 40 | "version": "0.5.1", 41 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.5.1.tgz", 42 | "integrity": "sha512-ONHr16SQvKZNSqjQT9gy5z24Jw+uqfO02/ngBSBoqChZ+W8qXX7GPRa1RoUnzGADw8K63R1BXUMzarCVQBpY8Q==", 43 | "requires": { 44 | "safer-buffer": ">= 2.1.2 < 3" 45 | } 46 | }, 47 | "is-property": { 48 | "version": "1.0.2", 49 | "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", 50 | "integrity": "sha1-V/4cTkhHTt1lsJkR8msc1Ald2oQ=" 51 | }, 52 | "long": { 53 | "version": "4.0.0", 54 | "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", 55 | "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==" 56 | }, 57 | "lru-cache": { 58 | "version": "5.1.1", 59 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", 60 | "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==", 61 | "requires": { 62 | "yallist": "^3.0.2" 63 | } 64 | }, 65 | "mysql2": { 66 | "version": "2.1.0", 67 | "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-2.1.0.tgz", 68 | "integrity": "sha512-9kGVyi930rG2KaHrz3sHwtc6K+GY9d8wWk1XRSYxQiunvGcn4DwuZxOwmK11ftuhhwrYDwGx9Ta4VBwznJn36A==", 69 | "requires": { 70 | "cardinal": "^2.1.1", 71 | "denque": "^1.4.1", 72 | "generate-function": "^2.3.1", 73 | "iconv-lite": "^0.5.0", 74 | "long": "^4.0.0", 75 | "lru-cache": "^5.1.1", 76 | "named-placeholders": "^1.1.2", 77 | "seq-queue": "^0.0.5", 78 | "sqlstring": "^2.3.1" 79 | } 80 | }, 81 | "named-placeholders": { 82 | "version": "1.1.2", 83 | "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.2.tgz", 84 | "integrity": "sha512-wiFWqxoLL3PGVReSZpjLVxyJ1bRqe+KKJVbr4hGs1KWfTZTQyezHFBbuKj9hsizHyGV2ne7EMjHdxEGAybD5SA==", 85 | "requires": { 86 | "lru-cache": "^4.1.3" 87 | }, 88 | "dependencies": { 89 | "lru-cache": { 90 | "version": "4.1.5", 91 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", 92 | "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", 93 | "requires": { 94 | "pseudomap": "^1.0.2", 95 | "yallist": "^2.1.2" 96 | } 97 | }, 98 | "yallist": { 99 | "version": "2.1.2", 100 | "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", 101 | "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=" 102 | } 103 | } 104 | }, 105 | "pseudomap": { 106 | "version": "1.0.2", 107 | "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", 108 | "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=" 109 | }, 110 | "redeyed": { 111 | "version": "2.1.1", 112 | "resolved": "https://registry.npmjs.org/redeyed/-/redeyed-2.1.1.tgz", 113 | "integrity": "sha1-iYS1gV2ZyyIEacme7v/jiRPmzAs=", 114 | "requires": { 115 | "esprima": "~4.0.0" 116 | } 117 | }, 118 | "safer-buffer": { 119 | "version": "2.1.2", 120 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 121 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" 122 | }, 123 | "seq-queue": { 124 | "version": "0.0.5", 125 | "resolved": "https://registry.npmjs.org/seq-queue/-/seq-queue-0.0.5.tgz", 126 | "integrity": "sha1-1WgS4cAXpuTnw+Ojeh2m143TyT4=" 127 | }, 128 | "sqlstring": { 129 | "version": "2.3.1", 130 | "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz", 131 | "integrity": "sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A=" 132 | }, 133 | "yallist": { 134 | "version": "3.1.1", 135 | "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", 136 | "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==" 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /Lecture15/mysql-intro/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mysql-intro", 3 | "version": "1.0.0", 4 | "description": "```shell mysql -u root -p # or mysql -u root #without password #or sudo mysql #on ubuntu ``` ### Create Database and User (inside MySQL)", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mysql2": "^2.1.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lecture15/mysql-intro/query.js: -------------------------------------------------------------------------------- 1 | const mysql = require('mysql2') 2 | 3 | const conn = mysql.createConnection({ 4 | host: 'localhost', 5 | user: 'mytestuser', 6 | password: 'mytestpass', 7 | database: 'mytestdb' 8 | }) 9 | 10 | conn.execute( 11 | `SELECT * FROM mysecondtable`, 12 | (err, rows, cols) => { 13 | if (err) throw err 14 | 15 | for (let row of rows) { 16 | console.log("================") 17 | for (let col of cols) { 18 | console.log(col.name, "\t:", row[col.name]) 19 | } 20 | console.log("================") 21 | } 22 | } 23 | ) -------------------------------------------------------------------------------- /Lecture15/sequelize-with-mysql/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sequelize-with-mysql", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@types/node": { 8 | "version": "13.7.4", 9 | "resolved": "https://registry.npmjs.org/@types/node/-/node-13.7.4.tgz", 10 | "integrity": "sha512-oVeL12C6gQS/GAExndigSaLxTrKpQPxewx9bOcwfvJiJge4rr7wNaph4J+ns5hrmIV2as5qxqN8YKthn9qh0jw==" 11 | }, 12 | "ansicolors": { 13 | "version": "0.3.2", 14 | "resolved": "https://registry.npmjs.org/ansicolors/-/ansicolors-0.3.2.tgz", 15 | "integrity": "sha1-ZlWX3oap/+Oqm/vmyuXG6kJrSXk=" 16 | }, 17 | "any-promise": { 18 | "version": "1.3.0", 19 | "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz", 20 | "integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8=" 21 | }, 22 | "bluebird": { 23 | "version": "3.7.2", 24 | "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", 25 | "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" 26 | }, 27 | "cardinal": { 28 | "version": "2.1.1", 29 | "resolved": "https://registry.npmjs.org/cardinal/-/cardinal-2.1.1.tgz", 30 | "integrity": "sha1-fMEFXYItISlU0HsIXeolHMe8VQU=", 31 | "requires": { 32 | "ansicolors": "~0.3.2", 33 | "redeyed": "~2.1.0" 34 | } 35 | }, 36 | "cls-bluebird": { 37 | "version": "2.1.0", 38 | "resolved": "https://registry.npmjs.org/cls-bluebird/-/cls-bluebird-2.1.0.tgz", 39 | "integrity": "sha1-N+8eCAqP+1XC9BZPU28ZGeeWiu4=", 40 | "requires": { 41 | "is-bluebird": "^1.0.2", 42 | "shimmer": "^1.1.0" 43 | } 44 | }, 45 | "debug": { 46 | "version": "4.1.1", 47 | "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", 48 | "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", 49 | "requires": { 50 | "ms": "^2.1.1" 51 | } 52 | }, 53 | "denque": { 54 | "version": "1.4.1", 55 | "resolved": "https://registry.npmjs.org/denque/-/denque-1.4.1.tgz", 56 | "integrity": "sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ==" 57 | }, 58 | "dottie": { 59 | "version": "2.0.2", 60 | "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.2.tgz", 61 | "integrity": "sha512-fmrwR04lsniq/uSr8yikThDTrM7epXHBAAjH9TbeH3rEA8tdCO7mRzB9hdmdGyJCxF8KERo9CITcm3kGuoyMhg==" 62 | }, 63 | "esprima": { 64 | "version": "4.0.1", 65 | "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", 66 | "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" 67 | }, 68 | "generate-function": { 69 | "version": "2.3.1", 70 | "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz", 71 | "integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==", 72 | "requires": { 73 | "is-property": "^1.0.2" 74 | } 75 | }, 76 | "iconv-lite": { 77 | "version": "0.5.1", 78 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.5.1.tgz", 79 | "integrity": "sha512-ONHr16SQvKZNSqjQT9gy5z24Jw+uqfO02/ngBSBoqChZ+W8qXX7GPRa1RoUnzGADw8K63R1BXUMzarCVQBpY8Q==", 80 | "requires": { 81 | "safer-buffer": ">= 2.1.2 < 3" 82 | } 83 | }, 84 | "inflection": { 85 | "version": "1.12.0", 86 | "resolved": "https://registry.npmjs.org/inflection/-/inflection-1.12.0.tgz", 87 | "integrity": "sha1-ogCTVlbW9fa8TcdQLhrstwMihBY=" 88 | }, 89 | "is-bluebird": { 90 | "version": "1.0.2", 91 | "resolved": "https://registry.npmjs.org/is-bluebird/-/is-bluebird-1.0.2.tgz", 92 | "integrity": "sha1-CWQ5Bg9KpBGr7hkUOoTWpVNG1uI=" 93 | }, 94 | "is-property": { 95 | "version": "1.0.2", 96 | "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", 97 | "integrity": "sha1-V/4cTkhHTt1lsJkR8msc1Ald2oQ=" 98 | }, 99 | "lodash": { 100 | "version": "4.17.15", 101 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", 102 | "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" 103 | }, 104 | "long": { 105 | "version": "4.0.0", 106 | "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", 107 | "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==" 108 | }, 109 | "lru-cache": { 110 | "version": "5.1.1", 111 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", 112 | "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==", 113 | "requires": { 114 | "yallist": "^3.0.2" 115 | } 116 | }, 117 | "moment": { 118 | "version": "2.24.0", 119 | "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", 120 | "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" 121 | }, 122 | "moment-timezone": { 123 | "version": "0.5.28", 124 | "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.28.tgz", 125 | "integrity": "sha512-TDJkZvAyKIVWg5EtVqRzU97w0Rb0YVbfpqyjgu6GwXCAohVRqwZjf4fOzDE6p1Ch98Sro/8hQQi65WDXW5STPw==", 126 | "requires": { 127 | "moment": ">= 2.9.0" 128 | } 129 | }, 130 | "ms": { 131 | "version": "2.1.2", 132 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", 133 | "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" 134 | }, 135 | "mysql2": { 136 | "version": "2.1.0", 137 | "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-2.1.0.tgz", 138 | "integrity": "sha512-9kGVyi930rG2KaHrz3sHwtc6K+GY9d8wWk1XRSYxQiunvGcn4DwuZxOwmK11ftuhhwrYDwGx9Ta4VBwznJn36A==", 139 | "requires": { 140 | "cardinal": "^2.1.1", 141 | "denque": "^1.4.1", 142 | "generate-function": "^2.3.1", 143 | "iconv-lite": "^0.5.0", 144 | "long": "^4.0.0", 145 | "lru-cache": "^5.1.1", 146 | "named-placeholders": "^1.1.2", 147 | "seq-queue": "^0.0.5", 148 | "sqlstring": "^2.3.1" 149 | } 150 | }, 151 | "named-placeholders": { 152 | "version": "1.1.2", 153 | "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.2.tgz", 154 | "integrity": "sha512-wiFWqxoLL3PGVReSZpjLVxyJ1bRqe+KKJVbr4hGs1KWfTZTQyezHFBbuKj9hsizHyGV2ne7EMjHdxEGAybD5SA==", 155 | "requires": { 156 | "lru-cache": "^4.1.3" 157 | }, 158 | "dependencies": { 159 | "lru-cache": { 160 | "version": "4.1.5", 161 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", 162 | "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", 163 | "requires": { 164 | "pseudomap": "^1.0.2", 165 | "yallist": "^2.1.2" 166 | } 167 | }, 168 | "yallist": { 169 | "version": "2.1.2", 170 | "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", 171 | "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=" 172 | } 173 | } 174 | }, 175 | "pseudomap": { 176 | "version": "1.0.2", 177 | "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", 178 | "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=" 179 | }, 180 | "redeyed": { 181 | "version": "2.1.1", 182 | "resolved": "https://registry.npmjs.org/redeyed/-/redeyed-2.1.1.tgz", 183 | "integrity": "sha1-iYS1gV2ZyyIEacme7v/jiRPmzAs=", 184 | "requires": { 185 | "esprima": "~4.0.0" 186 | } 187 | }, 188 | "retry-as-promised": { 189 | "version": "3.2.0", 190 | "resolved": "https://registry.npmjs.org/retry-as-promised/-/retry-as-promised-3.2.0.tgz", 191 | "integrity": "sha512-CybGs60B7oYU/qSQ6kuaFmRd9sTZ6oXSc0toqePvV74Ac6/IFZSI1ReFQmtCN+uvW1Mtqdwpvt/LGOiCBAY2Mg==", 192 | "requires": { 193 | "any-promise": "^1.3.0" 194 | } 195 | }, 196 | "safer-buffer": { 197 | "version": "2.1.2", 198 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 199 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" 200 | }, 201 | "semver": { 202 | "version": "6.3.0", 203 | "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", 204 | "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" 205 | }, 206 | "seq-queue": { 207 | "version": "0.0.5", 208 | "resolved": "https://registry.npmjs.org/seq-queue/-/seq-queue-0.0.5.tgz", 209 | "integrity": "sha1-1WgS4cAXpuTnw+Ojeh2m143TyT4=" 210 | }, 211 | "sequelize": { 212 | "version": "5.21.5", 213 | "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-5.21.5.tgz", 214 | "integrity": "sha512-n9hR5K4uQGmBGK/Y/iqewCeSFmKVsd0TRnh0tfoLoAkmXbKC4tpeK96RhKs7d+TTMtrJlgt2TNLVBaAxEwC4iw==", 215 | "requires": { 216 | "bluebird": "^3.5.0", 217 | "cls-bluebird": "^2.1.0", 218 | "debug": "^4.1.1", 219 | "dottie": "^2.0.0", 220 | "inflection": "1.12.0", 221 | "lodash": "^4.17.15", 222 | "moment": "^2.24.0", 223 | "moment-timezone": "^0.5.21", 224 | "retry-as-promised": "^3.2.0", 225 | "semver": "^6.3.0", 226 | "sequelize-pool": "^2.3.0", 227 | "toposort-class": "^1.0.1", 228 | "uuid": "^3.3.3", 229 | "validator": "^10.11.0", 230 | "wkx": "^0.4.8" 231 | } 232 | }, 233 | "sequelize-pool": { 234 | "version": "2.3.0", 235 | "resolved": "https://registry.npmjs.org/sequelize-pool/-/sequelize-pool-2.3.0.tgz", 236 | "integrity": "sha512-Ibz08vnXvkZ8LJTiUOxRcj1Ckdn7qafNZ2t59jYHMX1VIebTAOYefWdRYFt6z6+hy52WGthAHAoLc9hvk3onqA==" 237 | }, 238 | "shimmer": { 239 | "version": "1.2.1", 240 | "resolved": "https://registry.npmjs.org/shimmer/-/shimmer-1.2.1.tgz", 241 | "integrity": "sha512-sQTKC1Re/rM6XyFM6fIAGHRPVGvyXfgzIDvzoq608vM+jeyVD0Tu1E6Np0Kc2zAIFWIj963V2800iF/9LPieQw==" 242 | }, 243 | "sqlstring": { 244 | "version": "2.3.1", 245 | "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz", 246 | "integrity": "sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A=" 247 | }, 248 | "toposort-class": { 249 | "version": "1.0.1", 250 | "resolved": "https://registry.npmjs.org/toposort-class/-/toposort-class-1.0.1.tgz", 251 | "integrity": "sha1-f/0feMi+KMO6Rc1OGj9e4ZO9mYg=" 252 | }, 253 | "uuid": { 254 | "version": "3.4.0", 255 | "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", 256 | "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==" 257 | }, 258 | "validator": { 259 | "version": "10.11.0", 260 | "resolved": "https://registry.npmjs.org/validator/-/validator-10.11.0.tgz", 261 | "integrity": "sha512-X/p3UZerAIsbBfN/IwahhYaBbY68EN/UQBWHtsbXGT5bfrH/p4NQzUCG1kF/rtKaNpnJ7jAu6NGTdSNtyNIXMw==" 262 | }, 263 | "wkx": { 264 | "version": "0.4.8", 265 | "resolved": "https://registry.npmjs.org/wkx/-/wkx-0.4.8.tgz", 266 | "integrity": "sha512-ikPXMM9IR/gy/LwiOSqWlSL3X/J5uk9EO2hHNRXS41eTLXaUFEVw9fn/593jW/tE5tedNg8YjT5HkCa4FqQZyQ==", 267 | "requires": { 268 | "@types/node": "*" 269 | } 270 | }, 271 | "yallist": { 272 | "version": "3.1.1", 273 | "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", 274 | "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==" 275 | } 276 | } 277 | } 278 | -------------------------------------------------------------------------------- /Lecture15/sequelize-with-mysql/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sequelize-with-mysql", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mysql2": "^2.1.0", 13 | "sequelize": "^5.21.5" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lecture15/sequelize-with-mysql/read.js: -------------------------------------------------------------------------------- 1 | const Sequelize = require('sequelize') 2 | const util = require('util') 3 | 4 | const db = new Sequelize({ 5 | dialect: 'mysql', 6 | username: 'mytestuser', 7 | password: 'mytestpass', 8 | database: 'mytestdb', 9 | }) 10 | 11 | const Users = db.define('user', { 12 | id: { 13 | type: Sequelize.INTEGER, 14 | primaryKey: true, 15 | autoIncrement: true 16 | }, 17 | name: { 18 | type: Sequelize.STRING(50), 19 | allowNull: false 20 | }, 21 | email: { 22 | type: Sequelize.STRING(100), 23 | unique: true 24 | } 25 | }) 26 | 27 | async function dbOps() { 28 | await db.sync() 29 | const users = await Users.findAll({ 30 | where: { 31 | [Sequelize.Op.or]: [ 32 | {name: { [Sequelize.Op.like]: 'S%' }}, 33 | {email: { [Sequelize.Op.like]: 'h%' }} 34 | ] 35 | } 36 | }) 37 | for (let user of users) { 38 | console.log(user.name) 39 | } 40 | } 41 | 42 | dbOps() -------------------------------------------------------------------------------- /Lecture15/sequelize-with-mysql/write.js: -------------------------------------------------------------------------------- 1 | const Sequelize = require('sequelize') 2 | const util = require('util') 3 | 4 | const db = new Sequelize({ 5 | dialect: 'mysql', 6 | username: 'mytestuser', 7 | password: 'mytestpass', 8 | database: 'mytestdb', 9 | }) 10 | 11 | const Users = db.define('user', { 12 | id: { 13 | type: Sequelize.INTEGER, 14 | primaryKey: true, 15 | autoIncrement: true 16 | }, 17 | name: { 18 | type: Sequelize.STRING(50), 19 | allowNull: false 20 | }, 21 | email: { 22 | type: Sequelize.STRING(100), 23 | unique: true 24 | } 25 | }) 26 | 27 | async function dbOps() { 28 | await db.sync() 29 | const user = await Users.create({ 30 | name: 'Nancy', email: 'nancy@cb.lk' 31 | }) 32 | 33 | console.log(user) 34 | console.log('========================') 35 | user.name = user.name.toUpperCase() 36 | await (util.promisify(setTimeout))(5000) 37 | console.log(user) 38 | console.log('========================') 39 | await user.save() 40 | console.log(user) 41 | 42 | } 43 | 44 | dbOps() -------------------------------------------------------------------------------- /Lecture16/intro-mongodb/.gitignore: -------------------------------------------------------------------------------- 1 | data/ -------------------------------------------------------------------------------- /Lecture16/intro-mongodb/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "requires": true, 3 | "lockfileVersion": 1, 4 | "dependencies": { 5 | "bl": { 6 | "version": "2.2.0", 7 | "resolved": "https://registry.npmjs.org/bl/-/bl-2.2.0.tgz", 8 | "integrity": "sha512-wbgvOpqopSr7uq6fJrLH8EsvYMJf9gzfo2jCsL2eTy75qXPukA4pCgHamOQkZtY5vmfVtjB+P3LNlMHW5CEZXA==", 9 | "requires": { 10 | "readable-stream": "^2.3.5", 11 | "safe-buffer": "^5.1.1" 12 | } 13 | }, 14 | "bson": { 15 | "version": "1.1.3", 16 | "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.3.tgz", 17 | "integrity": "sha512-TdiJxMVnodVS7r0BdL42y/pqC9cL2iKynVwA0Ho3qbsQYr428veL3l7BQyuqiw+Q5SqqoT0m4srSY/BlZ9AxXg==" 18 | }, 19 | "core-util-is": { 20 | "version": "1.0.2", 21 | "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", 22 | "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" 23 | }, 24 | "denque": { 25 | "version": "1.4.1", 26 | "resolved": "https://registry.npmjs.org/denque/-/denque-1.4.1.tgz", 27 | "integrity": "sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ==" 28 | }, 29 | "inherits": { 30 | "version": "2.0.4", 31 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", 32 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" 33 | }, 34 | "isarray": { 35 | "version": "1.0.0", 36 | "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", 37 | "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" 38 | }, 39 | "memory-pager": { 40 | "version": "1.5.0", 41 | "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", 42 | "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", 43 | "optional": true 44 | }, 45 | "mongodb": { 46 | "version": "3.5.3", 47 | "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.5.3.tgz", 48 | "integrity": "sha512-II7P7A3XUdPiXRgcN96qIoRa1oesM6qLNZkzfPluNZjVkgQk3jnQwOT6/uDk4USRDTTLjNFw2vwfmbRGTA7msg==", 49 | "requires": { 50 | "bl": "^2.2.0", 51 | "bson": "^1.1.1", 52 | "denque": "^1.4.1", 53 | "require_optional": "^1.0.1", 54 | "safe-buffer": "^5.1.2", 55 | "saslprep": "^1.0.0" 56 | } 57 | }, 58 | "process-nextick-args": { 59 | "version": "2.0.1", 60 | "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", 61 | "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" 62 | }, 63 | "readable-stream": { 64 | "version": "2.3.7", 65 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", 66 | "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", 67 | "requires": { 68 | "core-util-is": "~1.0.0", 69 | "inherits": "~2.0.3", 70 | "isarray": "~1.0.0", 71 | "process-nextick-args": "~2.0.0", 72 | "safe-buffer": "~5.1.1", 73 | "string_decoder": "~1.1.1", 74 | "util-deprecate": "~1.0.1" 75 | }, 76 | "dependencies": { 77 | "safe-buffer": { 78 | "version": "5.1.2", 79 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 80 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 81 | } 82 | } 83 | }, 84 | "require_optional": { 85 | "version": "1.0.1", 86 | "resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz", 87 | "integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==", 88 | "requires": { 89 | "resolve-from": "^2.0.0", 90 | "semver": "^5.1.0" 91 | } 92 | }, 93 | "resolve-from": { 94 | "version": "2.0.0", 95 | "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz", 96 | "integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c=" 97 | }, 98 | "safe-buffer": { 99 | "version": "5.2.0", 100 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", 101 | "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==" 102 | }, 103 | "saslprep": { 104 | "version": "1.0.3", 105 | "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz", 106 | "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==", 107 | "optional": true, 108 | "requires": { 109 | "sparse-bitfield": "^3.0.3" 110 | } 111 | }, 112 | "semver": { 113 | "version": "5.7.1", 114 | "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", 115 | "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" 116 | }, 117 | "sparse-bitfield": { 118 | "version": "3.0.3", 119 | "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", 120 | "integrity": "sha1-/0rm5oZWBWuks+eSqzM004JzyhE=", 121 | "optional": true, 122 | "requires": { 123 | "memory-pager": "^1.0.2" 124 | } 125 | }, 126 | "string_decoder": { 127 | "version": "1.1.1", 128 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", 129 | "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", 130 | "requires": { 131 | "safe-buffer": "~5.1.0" 132 | }, 133 | "dependencies": { 134 | "safe-buffer": { 135 | "version": "5.1.2", 136 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 137 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 138 | } 139 | } 140 | }, 141 | "util-deprecate": { 142 | "version": "1.0.2", 143 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", 144 | "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /Lecture16/intro-mongodb/read-promises.js: -------------------------------------------------------------------------------- 1 | const MongoClient = require('mongodb').MongoClient 2 | 3 | const MONGO_URL = "mongodb://localhost:27017" 4 | 5 | async function write () { 6 | const client = await MongoClient.connect(MONGO_URL) 7 | 8 | const blogDB = client.db('blog') 9 | const articles = blogDB.collection('articles') 10 | 11 | const rows = await articles.find({ 12 | a: { $exists: true } 13 | }).toArray() 14 | console.log(rows) 15 | } 16 | 17 | write() -------------------------------------------------------------------------------- /Lecture16/intro-mongodb/write-promise.js: -------------------------------------------------------------------------------- 1 | const MongoClient = require('mongodb').MongoClient 2 | 3 | const MONGO_URL = "mongodb://localhost:27017" 4 | 5 | async function write () { 6 | const client = await MongoClient.connect(MONGO_URL) 7 | 8 | const blogDB = client.db('blog') 9 | const articles = blogDB.collection('articles') 10 | 11 | const result = await articles.insertOne({ 12 | a: 10 13 | }) 14 | console.log(result.ops) 15 | } 16 | 17 | write() -------------------------------------------------------------------------------- /Lecture16/intro-mongodb/write.js: -------------------------------------------------------------------------------- 1 | const MongoClient = require('mongodb').MongoClient 2 | 3 | const MONGO_URL = "mongodb://localhost:27017" 4 | MongoClient.connect(MONGO_URL, (err, client) => { 5 | 6 | const blogDB = client.db('blog') 7 | const articles = blogDB.collection('articles') 8 | 9 | articles.insertOne({ 10 | title: 'Lorem Ipsum is therefore always free ', 11 | body: 'ney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a', 12 | subtitle: 'l text, and a search fo', 13 | category: 'humour' 14 | }, (err, result) => { 15 | if (err) throw err 16 | 17 | console.log(result.ops) 18 | }) 19 | }) -------------------------------------------------------------------------------- /Lecture17/blog-project/controllers/articles.js: -------------------------------------------------------------------------------- 1 | const { Articles } = require('../data/db') 2 | 3 | async function createArticle(article) { 4 | if (!article.title) { 5 | return new Error('title missing') 6 | } 7 | if (!article.body) { 8 | return new Error('body missing') 9 | } 10 | 11 | await Articles.create({ 12 | title: article.title, 13 | //...other fields 14 | }) 15 | } 16 | 17 | module.exports = { 18 | createArticle 19 | } -------------------------------------------------------------------------------- /Lecture17/blog-project/controllers/users.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-blocks-archives/Webdev_Pitampura_2019_December/79d23ff5c1d9685bb215e1a58bdd1255461d52fd/Lecture17/blog-project/controllers/users.js -------------------------------------------------------------------------------- /Lecture17/blog-project/data/db.js: -------------------------------------------------------------------------------- 1 | const Sequelize = require('sequelize') 2 | 3 | const db = new Sequelize({ 4 | // db config 5 | }) 6 | 7 | 8 | const Users = db.define('user', { 9 | // config here 10 | }) 11 | 12 | const Articles = db.define('user', { 13 | // config here 14 | }) 15 | 16 | module.exports = { 17 | db, 18 | Users, 19 | Articles 20 | } -------------------------------------------------------------------------------- /Lecture17/blog-project/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "blog-project", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "dependencies": { 7 | "express": "^4.17.1", 8 | "mysql": "^2.18.1", 9 | "sequelize": "^5.21.5" 10 | }, 11 | "devDependencies": {}, 12 | "scripts": { 13 | "test": "echo \"Error: no test specified\" && exit 1" 14 | }, 15 | "author": "", 16 | "license": "ISC" 17 | } 18 | -------------------------------------------------------------------------------- /Lecture17/blog-project/routes/api/articles.js: -------------------------------------------------------------------------------- 1 | const { Router } = require('express') 2 | const { createArticle } = require('../../controllers/articles') 3 | 4 | const route = Router() 5 | 6 | // GET /api/articles 7 | route.get('/', (req, res) => { 8 | res.send('TODO: list of all articles') 9 | }) 10 | 11 | // POST /api/articles 12 | route.post('/', (req, res) => { 13 | res.send('TODO: article has been added') 14 | 15 | createArticle({ 16 | title: req.body.title, 17 | // ... other fields 18 | }) 19 | }) 20 | 21 | module.exports = { route } -------------------------------------------------------------------------------- /Lecture17/blog-project/routes/api/index.js: -------------------------------------------------------------------------------- 1 | const { Router } = require('express') 2 | 3 | const articlesRoute = require('./articles').route 4 | const profilesRoute = require('./profiles').route 5 | 6 | const route = Router() 7 | 8 | route.use('/articles', articlesRoute) 9 | route.use('/profiles', profilesRoute) 10 | 11 | 12 | module.exports = { route } -------------------------------------------------------------------------------- /Lecture17/blog-project/routes/api/profiles.js: -------------------------------------------------------------------------------- 1 | const { Router } = require('express') 2 | 3 | const route = Router() 4 | 5 | // GET /api/profiles/:username 6 | route.get('/:username', (req, res) => { 7 | res.send('TODO: profile page of ' + req.params.username) 8 | }) 9 | 10 | module.exports = { route } -------------------------------------------------------------------------------- /Lecture17/blog-project/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const { db } = require('./data/db') 3 | const apiRoute = require('./routes/api').route 4 | 5 | const app = express() 6 | 7 | app.use('/api', apiRoute) 8 | 9 | 10 | db.sync().then(() => { 11 | app.listen(7878, () => { 12 | console.log('started on http://localhost:7878') 13 | }) 14 | }) 15 | -------------------------------------------------------------------------------- /Lecture17/session-management/db.js: -------------------------------------------------------------------------------- 1 | const Seqeulize = require('sequelize') 2 | 3 | const db = new Seqeulize({ 4 | dialect: 'mysql', 5 | database: 'webdevsampledb', 6 | username: 'webdevuser', 7 | password: 'webdevpass' 8 | }) 9 | 10 | const Users = db.define('user', { 11 | username: { 12 | type: Seqeulize.STRING(30), 13 | primaryKey: true 14 | }, 15 | email: { 16 | type: Seqeulize.STRING(75), 17 | allowNull: false, 18 | unique: true 19 | }, 20 | name: { 21 | type: Seqeulize.STRING 22 | }, 23 | password: { 24 | type: Seqeulize.STRING, 25 | allowNull: false 26 | } 27 | }) 28 | 29 | module.exports = { 30 | db, Users 31 | } -------------------------------------------------------------------------------- /Lecture17/session-management/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "session-management", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "server.js", 6 | "dependencies": { 7 | "express": "^4.17.1", 8 | "express-session": "^1.17.0", 9 | "hbs": "^4.1.0", 10 | "mysql2": "^2.1.0", 11 | "sequelize": "^5.21.5" 12 | }, 13 | "devDependencies": {}, 14 | "scripts": { 15 | "test": "echo \"Error: no test specified\" && exit 1", 16 | "start": "node server.js" 17 | }, 18 | "author": "", 19 | "license": "ISC" 20 | } 21 | -------------------------------------------------------------------------------- /Lecture17/session-management/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const session = require('express-session') 3 | const { db, Users } = require('./db') 4 | 5 | const app = express() 6 | app.set('view engine', 'hbs') 7 | app.use(express.urlencoded({ extended: true })) 8 | app.use( 9 | session({ 10 | secret: 'a long unguessable string here', 11 | resave: false, 12 | saveUninitialized: true, 13 | cookie: { 14 | httpOnly: false 15 | } 16 | }) 17 | ) 18 | 19 | app.get('/view', (req, res) => { 20 | console.log(req.session) 21 | if (req.session.count) { 22 | req.session.count++ 23 | } else { 24 | req.session.count = 1 25 | } 26 | req.session.save() 27 | res.render('viewcounter', { 28 | count: req.session.count 29 | }) 30 | }) 31 | 32 | app.get('/signup', (req, res) => { 33 | res.render('signup') 34 | }) 35 | 36 | app.post('/signup', async (req, res) => { 37 | const user = await Users.create({ 38 | username: req.body.username, 39 | password: req.body.password, 40 | email: req.body.email, 41 | name: req.body.name 42 | }) 43 | res.redirect('/login') 44 | }) 45 | 46 | app.get('/login', (req, res) => { 47 | res.render('login') 48 | }) 49 | 50 | app.post('/login', async (req, res) => { 51 | const user = await Users.findOne({ 52 | where: { 53 | username: req.body.username 54 | } 55 | }) 56 | 57 | if (!user) { 58 | res.send('Wrong username') 59 | return 60 | } 61 | 62 | if (user.password != req.body.password) { 63 | res.send('Wrong password') 64 | return 65 | } 66 | 67 | req.session.username = user.username 68 | req.session.save() 69 | 70 | res.redirect('/profile') 71 | }) 72 | 73 | app.get('/profile', async (req, res) => { 74 | if (!req.session.username) { 75 | res.redirect('/login') 76 | return 77 | } 78 | 79 | const user = await Users.findOne({ 80 | where: { 81 | username: req.session.username 82 | } 83 | }) 84 | 85 | res.render('profile', { user }) 86 | }) 87 | 88 | db.sync().then(() => { 89 | app.listen(3131, () => { 90 | console.log('started on http://localhost:3131/') 91 | }) 92 | }) 93 | -------------------------------------------------------------------------------- /Lecture17/session-management/views/login.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 |

    Login

    10 | 11 |
    12 | 13 |
    14 | 15 |
    16 | 17 | 18 |
    19 | 20 | -------------------------------------------------------------------------------- /Lecture17/session-management/views/profile.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 |

    Profile

    10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
    Name{{user.name}}
    Username{{user.username}}
    Email{{user.email}}
    31 | 32 | -------------------------------------------------------------------------------- /Lecture17/session-management/views/signup.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 |

    Signup

    10 | 11 |
    12 | 13 |
    14 | 15 |
    16 | 17 |
    18 | 19 |
    20 | 21 |
    22 | 23 | -------------------------------------------------------------------------------- /Lecture17/session-management/views/viewcounter.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 |

    Hello

    10 |
    Welcome to our site !
    11 |
    You have visited us {{count}} times
    12 | 13 | -------------------------------------------------------------------------------- /Lecture18/blog-project/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ### Database Setup 4 | 5 | ```mysql 6 | create database realworldio; 7 | create user conduit identified with mysql_native_password by 'conduit'; 8 | grant all privileges on realworldio.* to conduit; 9 | flush privileges; 10 | ``` 11 | 12 | ### PostMan Collection 13 | 14 | -------------------------------------------------------------------------------- /Lecture18/blog-project/controllers/articles.js: -------------------------------------------------------------------------------- 1 | const { Articles, Users } = require('../data/db') 2 | const { slugify } = require('../utils/string') 3 | 4 | async function getAllArticles() { 5 | const articles = await Articles.findAll({ 6 | attributes: [ 7 | 'slug', 'title', 'description', 8 | 'body', 'createdAt', 'updatedAt' 9 | ], 10 | include: [{ 11 | attributes: ['username', 'bio', 'image'], 12 | model: Users, 13 | as: 'author' 14 | }] 15 | }) 16 | 17 | return ({ 18 | articles, 19 | articlesCount: articles.length 20 | }) 21 | } 22 | 23 | async function createArticle( 24 | title, 25 | description, 26 | body, 27 | authorUsername 28 | ) { 29 | if (!title) { 30 | return new Error('title missing') 31 | } 32 | if (!body) { 33 | return new Error('body missing') 34 | } 35 | 36 | const newArticle = await Articles.create({ 37 | slug: slugify(title), 38 | title, 39 | description, 40 | body, 41 | authorUsername 42 | }) 43 | 44 | const article = await Articles.findOne({ 45 | attributes: [ 46 | 'slug', 'title', 'description', 47 | 'body', 'createdAt', 'updatedAt' 48 | ], 49 | where: {slug: newArticle.slug}, 50 | include: [{ 51 | attributes: ['username', 'bio', 'image'], 52 | model: Users, 53 | as: 'author' 54 | }] 55 | }) 56 | return article 57 | } 58 | 59 | module.exports = { 60 | getAllArticles, 61 | createArticle 62 | } -------------------------------------------------------------------------------- /Lecture18/blog-project/controllers/users.js: -------------------------------------------------------------------------------- 1 | const { Users } = require('../data/db') 2 | const { genRandomString } = require('../utils/random') 3 | 4 | async function createUser(username, email, password, bio, image) { 5 | // TODO: validate username, email, password not null 6 | const user = await Users.create({ 7 | username, 8 | email, 9 | password, 10 | token: genRandomString(32), 11 | bio, 12 | image 13 | }) 14 | 15 | return user 16 | } 17 | 18 | async function authUser(username, password) { 19 | const user = await Users.findOne({ 20 | where: { username } 21 | }) 22 | if (!user) { 23 | return { body: [ 'No user found with that username' ]} 24 | } 25 | if (user.password != password) { 26 | return { body: [ 'Password does not match' ]} 27 | } 28 | return user 29 | } 30 | 31 | async function findUserByToken(token) { 32 | const user = await Users.findOne({ 33 | where: { token } 34 | }) 35 | 36 | if (!user) { 37 | return { body: [ 'Invalid token' ]} 38 | } 39 | 40 | return user 41 | } 42 | 43 | module.exports = { 44 | createUser, 45 | authUser, 46 | findUserByToken 47 | } -------------------------------------------------------------------------------- /Lecture18/blog-project/data/blog.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-blocks-archives/Webdev_Pitampura_2019_December/79d23ff5c1d9685bb215e1a58bdd1255461d52fd/Lecture18/blog-project/data/blog.db -------------------------------------------------------------------------------- /Lecture18/blog-project/data/db.js: -------------------------------------------------------------------------------- 1 | const Sequelize = require('sequelize') 2 | 3 | const db = new Sequelize({ 4 | dialect: 'sqlite', 5 | storage: __dirname + '/blog.db', 6 | database: 'realworldio', 7 | username: 'conduit', 8 | password: 'conduit' 9 | }) 10 | 11 | 12 | const Users = db.define('user', { 13 | email: { 14 | type: Sequelize.STRING, 15 | unique: true, 16 | allowNull: false 17 | }, 18 | username: { 19 | type: Sequelize.STRING, 20 | primaryKey: true 21 | }, 22 | password: { 23 | type: Sequelize.STRING, 24 | allowNull: false, 25 | }, 26 | token: { 27 | type: Sequelize.STRING(32), 28 | allowNull: false 29 | }, 30 | bio: { 31 | type: Sequelize.TEXT 32 | }, 33 | image: { 34 | type: Sequelize.STRING 35 | } 36 | }) 37 | 38 | const Articles = db.define('article', { 39 | "slug": { 40 | type: Sequelize.STRING(100), 41 | primaryKey: true 42 | }, 43 | "title": { 44 | type: Sequelize.STRING, 45 | allowNull: false 46 | }, 47 | "description": { 48 | type: Sequelize.STRING 49 | }, 50 | "body": { 51 | type: Sequelize.TEXT 52 | }, 53 | // TODO: Add favourites fields 54 | }) 55 | 56 | Articles.belongsTo(Users, { as: 'author'}) 57 | Users.hasMany(Articles, { as: 'author'}) 58 | 59 | module.exports = { 60 | db, 61 | Users, 62 | Articles 63 | } -------------------------------------------------------------------------------- /Lecture18/blog-project/middlewares/auth.js: -------------------------------------------------------------------------------- 1 | const {findUserByToken} = require('../controllers/users') 2 | 3 | async function userFromToken(req, res, next) { 4 | 5 | let auth = req.headers['authorization'] 6 | 7 | if (auth && auth.startsWith('Token ')) { 8 | let token = auth.split(' ')[1] 9 | let user = await findUserByToken(token) 10 | if (user) { 11 | req.user = user 12 | return next() 13 | } 14 | } 15 | 16 | res.status(401).send({ 17 | errors: { 18 | body: ['Invalid authorization code'] 19 | } 20 | }) 21 | } 22 | 23 | module.exports = { userFromToken } -------------------------------------------------------------------------------- /Lecture18/blog-project/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "blog-project", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "dependencies": { 7 | "express": "^4.17.1", 8 | "mysql2": "^2.1.0", 9 | "sequelize": "^5.21.5", 10 | "sqlite3": "^4.1.1" 11 | }, 12 | "devDependencies": {}, 13 | "scripts": { 14 | "test": "echo \"Error: no test specified\" && exit 1" 15 | }, 16 | "author": "", 17 | "license": "ISC" 18 | } 19 | -------------------------------------------------------------------------------- /Lecture18/blog-project/routes/api/articles.js: -------------------------------------------------------------------------------- 1 | const { Router } = require('express') 2 | const { userFromToken } = require('../../middlewares/auth') 3 | const { getAllArticles, createArticle } = require('../../controllers/articles') 4 | const { findUserByToken } = require('../../controllers/users') 5 | const route = Router() 6 | 7 | // GET /api/articles 8 | route.get('/', async (req, res) => { 9 | const articles = await getAllArticles() 10 | 11 | res.send(articles) 12 | }) 13 | 14 | // POST /api/articles 15 | route.post('/', userFromToken, async (req, res) => { 16 | 17 | let a = req.body.article 18 | let article = await createArticle( 19 | a.title, 20 | a.description, 21 | a.body, 22 | req.user.username 23 | ) 24 | res.send(article) 25 | }) 26 | 27 | module.exports = { route } 28 | -------------------------------------------------------------------------------- /Lecture18/blog-project/routes/api/index.js: -------------------------------------------------------------------------------- 1 | const { Router } = require('express') 2 | 3 | const articlesRoute = require('./articles').route 4 | const profilesRoute = require('./profiles').route 5 | const usersRoute = require('./users').route 6 | const userRoute = require('./user').route 7 | 8 | const route = Router() 9 | 10 | route.use('/articles', articlesRoute) 11 | route.use('/profiles', profilesRoute) 12 | route.use('/users', usersRoute) 13 | route.use('/user', userRoute) 14 | 15 | 16 | module.exports = { route } -------------------------------------------------------------------------------- /Lecture18/blog-project/routes/api/profiles.js: -------------------------------------------------------------------------------- 1 | const { Router } = require('express') 2 | 3 | const route = Router() 4 | 5 | // GET /api/profiles/:username 6 | route.get('/:username', (req, res) => { 7 | res.send('TODO: profile page of ' + req.params.username) 8 | }) 9 | 10 | module.exports = { route } -------------------------------------------------------------------------------- /Lecture18/blog-project/routes/api/user.js: -------------------------------------------------------------------------------- 1 | const { Router } = require('express') 2 | const { userFromToken } = require('../../middlewares/auth') 3 | const { 4 | createUser, 5 | authUser, 6 | findUserByToken 7 | } = require('../../controllers/users') 8 | 9 | const route = Router() 10 | 11 | // GET /api/user 12 | route.get('/', userFromToken, async (req, res) => { 13 | return res.send(req.user) 14 | }) 15 | 16 | module.exports = { route } -------------------------------------------------------------------------------- /Lecture18/blog-project/routes/api/users.js: -------------------------------------------------------------------------------- 1 | const { Router } = require('express') 2 | const { 3 | createUser, 4 | authUser 5 | } = require('../../controllers/users') 6 | 7 | const route = Router() 8 | 9 | // POST /api/users 10 | route.post('/', async (req, res) => { 11 | let u = req.body.user 12 | const user = await createUser( 13 | u.username, 14 | u.email, 15 | u.password, 16 | u.bio, 17 | u.image 18 | ) 19 | 20 | res.send(user) 21 | 22 | }) 23 | 24 | module.exports = { route } -------------------------------------------------------------------------------- /Lecture18/blog-project/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const { db } = require('./data/db') 3 | const apiRoute = require('./routes/api').route 4 | 5 | const app = express() 6 | 7 | app.use(express.json()) 8 | app.use('/api', apiRoute) 9 | 10 | 11 | db.sync().then(() => { 12 | app.listen(7878, () => { 13 | console.log('started on http://localhost:7878') 14 | }) 15 | }) 16 | -------------------------------------------------------------------------------- /Lecture18/blog-project/utils/random.js: -------------------------------------------------------------------------------- 1 | const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' 2 | 3 | function genRandomString(length) { 4 | let buff = [] 5 | while (buff.length < length) { 6 | const charCode = parseInt(Math.random() * (61)) 7 | buff.push(ALPHABET.charAt(charCode)) 8 | } 9 | return buff.join('') 10 | } 11 | 12 | module.exports = { 13 | genRandomString 14 | } -------------------------------------------------------------------------------- /Lecture18/blog-project/utils/string.js: -------------------------------------------------------------------------------- 1 | 2 | function slugify(title) { 3 | return title.toLowerCase().split(' ').join('-') 4 | } 5 | 6 | module.exports = { 7 | slugify 8 | } -------------------------------------------------------------------------------- /Lecture19/websockets/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "websockets", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "node server.js" 9 | }, 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "express": "^4.17.1", 14 | "socket.io": "^2.3.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lecture19/websockets/public/chat.js: -------------------------------------------------------------------------------- 1 | const socket = io() 2 | 3 | $(() => { 4 | $('#beep').mousedown(() => { 5 | socket.emit('beep', { state: 'on' }) 6 | }) 7 | $('#beep').mouseup(() => { 8 | socket.emit('beep', { state: 'off' }) 9 | }) 10 | 11 | $('#send').click(() => { 12 | let msg = $('#msg').val() 13 | if (msg) { 14 | socket.emit('msg_send', { msg: msg }) 15 | $('#msg').val('') 16 | } 17 | }) 18 | 19 | socket.on('msg_rcvd', data => { 20 | $('#chatbox').append($('
    ').text(data.msg)) 21 | }) 22 | 23 | socket.on('beep', data => { 24 | let status = $('#' + data.id) 25 | if (!status[0]) { 26 | $('#statusbox').append( 27 | $(`
    `).text(data.id) 28 | ) 29 | status = $('#' + data.id) 30 | } 31 | 32 | status.css( 33 | 'background-color', 34 | data.state == 'on' ? 'green' : 'red' 35 | ) 36 | }) 37 | }) 38 | -------------------------------------------------------------------------------- /Lecture19/websockets/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 | 10 | 11 | 12 | 13 |

    Chat Example

    14 |

    This is a chatting app

    15 | 16 | 17 |
    18 | 19 |
    20 | 21 |
    22 | 23 | 24 |
    25 | 26 |
    27 | 28 | -------------------------------------------------------------------------------- /Lecture19/websockets/public/style.css: -------------------------------------------------------------------------------- 1 | div.status { 2 | padding: 10px; 3 | width: 200px; 4 | margin: 10px; 5 | border: solid black 1px; 6 | } 7 | -------------------------------------------------------------------------------- /Lecture19/websockets/server.js: -------------------------------------------------------------------------------- 1 | // the express library 2 | const express = require('express') 3 | // the http library (comes with nodejs by default) 4 | const http = require('http') 5 | // the socket.io library 6 | const socketio = require('socket.io') 7 | 8 | const PORT = process.env.PORT || 5555 9 | 10 | // the express app 11 | const app = express() 12 | // the http server created with logic of the app 13 | const server = http.createServer(app) 14 | // the socket.io listener created on the server 15 | const io = socketio(server) 16 | 17 | app.use('/', express.static(__dirname + '/public')) 18 | 19 | io.on('connection', (socket) => { 20 | console.log('connection created', socket.id) 21 | 22 | socket.on('beep', (data) => { 23 | io.emit('beep', { 24 | state: data.state, 25 | id: socket.id 26 | }) 27 | }) 28 | 29 | socket.on('msg_send', (data) => { 30 | // io.emit('msg_rcvd', data) 31 | // io.to('').emit() 32 | socket.broadcast.emit('msg_rcvd', data) 33 | }) 34 | }) 35 | 36 | 37 | server.listen(PORT, () => { 38 | console.log(`started on http://localhost:${PORT}`) 39 | }) --------------------------------------------------------------------------------