<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Gkadri</id>
	<title>Soma-notes - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Gkadri"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php/Special:Contributions/Gkadri"/>
	<updated>2026-04-05T21:17:25Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2014W_Lecture_9&amp;diff=18710</id>
		<title>WebFund 2014W Lecture 9</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2014W_Lecture_9&amp;diff=18710"/>
		<updated>2014-03-02T01:57:41Z</updated>

		<summary type="html">&lt;p&gt;Gkadri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The video from the lecture given on February 5, 2014 is available:&lt;br /&gt;
* [http://www.screencast.com/t/W9rewtusggz Small from screencast.com]&lt;br /&gt;
* [http://www.screencast.com/t/cJmYPtR6 Large from screencast.com]&lt;br /&gt;
* [http://dl.cuol.ca/capture/Anil.Somayaji/COMP_2406_2014W_Lecture_9_-_20140205_143924_27.mp4 Original from CUOL]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Lecture Notes ==&lt;br /&gt;
&lt;br /&gt;
In this lecture the adventure-demo app of assignment 2 is explained. &lt;br /&gt;
&lt;br /&gt;
=== storeRooms.js ===&lt;br /&gt;
&lt;br /&gt;
storeRooms.js connects to the database and creates the collection called Rooms. If the collection table already exists, then it drops it. MongoDb stores the last room the player was at before leaving the game. Even if the server was killed and was started up again, it still remembers the last room of each player.&lt;br /&gt;
&lt;br /&gt;
It is important to note that &amp;lt;code&amp;gt;db.close();&amp;lt;/code&amp;gt; at the end of storeRooms.js terminates the node process. Node is designed to wait for the input/output connection to send an event. We need to include this line in App.js otherwise Node is going to be waiting for something to happen after the code gets executed as long as there is an open socket.&lt;br /&gt;
&lt;br /&gt;
=== App.js ===&lt;br /&gt;
&lt;br /&gt;
The variable &amp;lt;code&amp;gt;mongoStore&amp;lt;/code&amp;gt; declared at:&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; var MongoStore = require(&#039;connect-mongo&#039;)(express);&lt;br /&gt;
&lt;br /&gt;
was used at: &lt;br /&gt;
&lt;br /&gt;
 &amp;gt; app.use(express.session({&lt;br /&gt;
 &amp;gt; cookie: {maxAge: 60000 * 20} // 20 minutes&lt;br /&gt;
 &amp;gt; , secret: &amp;quot;Shh... I&#039;m a secret&amp;quot;&lt;br /&gt;
 &amp;gt; , store: new MongoStore({db: &amp;quot;adventure-demo&amp;quot;})&lt;br /&gt;
 &amp;gt; }));&lt;br /&gt;
&lt;br /&gt;
The piece of code above provides session support and it is there to have cookies used when handling requests from the browser. Without sessions, there is no other way for the web app to know if the player is logged in or not.&lt;br /&gt;
&lt;br /&gt;
The following line specifies how long the cookies last:&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; cookie: {maxAge: 60000 * 20} // 20 minutes&lt;br /&gt;
&lt;br /&gt;
This following line :&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; store: new MongoStore({db: &amp;quot;adventure-demo&amp;quot;})&lt;br /&gt;
&lt;br /&gt;
is saying do not store the session in memory otherwise all sessions will be lost if the server was restarted. It is saying store the session in an instance of mongostore and the database to use is “adventure–demo”.&lt;br /&gt;
&lt;br /&gt;
It is important to note that, in app.js, the web server is being created and it runs first and then the rooms are getting added.&lt;br /&gt;
&lt;br /&gt;
=== Index.js ===&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; playersCollection.find({playername: playername}).toArray(addPlayer);&lt;br /&gt;
&lt;br /&gt;
finds the player collection having the player name similar to the content of the variable &amp;lt;code&amp;gt;playername&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;PlayerCollection.find({playername: playername})&amp;lt;/code&amp;gt; part returns a cursor object and the &amp;lt;code&amp;gt;toArray(addPlayer)&amp;lt;/code&amp;gt; part turns it into an array.&lt;br /&gt;
&lt;br /&gt;
While all static pages that are being served are in the public library, Jade templates are server side dynamic web pages. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Home.js ===&lt;br /&gt;
&lt;br /&gt;
The code in this file runs on the browser so it is a client-side code.&lt;br /&gt;
&lt;br /&gt;
=== Other Important Stuff: ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
• All of the available databases can be shown using the &amp;lt;code&amp;gt;show dbs&amp;lt;/code&amp;gt; mongo shell command (located in our mongodb installation directory and can be started by typing &amp;lt;code&amp;gt;./bin/mongo&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
• Collections of this database can be shown by typing &amp;lt;code&amp;gt;use adventure-demo&amp;lt;/code&amp;gt; then &amp;lt;code&amp;gt;show collections&amp;lt;/code&amp;gt; in mongo shell.&lt;br /&gt;
&lt;br /&gt;
• &amp;lt;code&amp;gt;db.sessions.find()&amp;lt;/code&amp;gt; shows the active sessions in the database.&lt;br /&gt;
&lt;br /&gt;
• &amp;lt;code&amp;gt;db.players.drop()&amp;lt;/code&amp;gt; deletes the players collection.&lt;br /&gt;
&lt;br /&gt;
• Note that when we try to access a collection that does not exist, Mongodb creates it.&lt;br /&gt;
&lt;br /&gt;
• Mongodb is not a part of node. It is a completely separate executable. Mongodb works well with node particularly because it uses JavaScript internally.&lt;br /&gt;
&lt;br /&gt;
• Next () is provided by the “connect” middleware and refers to the next middleware in the express stack.&lt;br /&gt;
&lt;br /&gt;
[http://stackoverflow.com/questions/8710669/having-a-hard-time-trying-to-understand-next-next-in-express-js Having a hard time trying to understand &#039;next/next()&#039; in express.js?]&lt;br /&gt;
&lt;br /&gt;
• Callbacks (as explained in an article posted on [http://javascriptissexy.com/understand-javascript-callback-functions-and-use-them/ javascriptissexy.com]):&lt;br /&gt;
&lt;br /&gt;
In JavaScript, functions are first-class objects, which means that they can be “stored in variables, passed as arguments to functions, created within functions, and returned from functions”&lt;br /&gt;
&lt;br /&gt;
A callback function is a function that is passed to another function (let’s call this other function “otherFunction”) as a parameter, and the callback function is called (executed) inside otherFunction.&lt;br /&gt;
&lt;br /&gt;
When we pass a callback function as an argument to another function, we are only passing the function definition. We are not executing the function in the parameter. We aren’t passing the function with the trailing pair of executing parenthesis () like we do when we are executing a function. And since the containing function has the callback function in its parameter as a function definition, it can execute the callback anytime. &lt;br /&gt;
&lt;br /&gt;
It is important to note that the callback function is not executed immediately. It is “called back” (hence the name) at some specified point inside the containing function’s body.&lt;/div&gt;</summary>
		<author><name>Gkadri</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2014W_Lecture_9&amp;diff=18709</id>
		<title>WebFund 2014W Lecture 9</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2014W_Lecture_9&amp;diff=18709"/>
		<updated>2014-03-02T01:56:38Z</updated>

		<summary type="html">&lt;p&gt;Gkadri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The video from the lecture given on February 5, 2014 is available:&lt;br /&gt;
* [http://www.screencast.com/t/W9rewtusggz Small from screencast.com]&lt;br /&gt;
* [http://www.screencast.com/t/cJmYPtR6 Large from screencast.com]&lt;br /&gt;
* [http://dl.cuol.ca/capture/Anil.Somayaji/COMP_2406_2014W_Lecture_9_-_20140205_143924_27.mp4 Original from CUOL]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Lecture Notes ==&lt;br /&gt;
&lt;br /&gt;
In this lecture the adventure-demo app of assignment 2 is explained. &lt;br /&gt;
&lt;br /&gt;
=== storeRooms.js ===&lt;br /&gt;
&lt;br /&gt;
storeRooms.js connects to the database and creates the collection called Rooms. If the collection table already exists, then it drops it. MongoDb stores the last room the player was at before leaving the game. Even if the server was killed and was started up again, it still remembers the last room of each player.&lt;br /&gt;
&lt;br /&gt;
It is important to note that &amp;lt;code&amp;gt;db.close();&amp;lt;/code&amp;gt; at the end of storeRooms.js terminates the node process. Node is designed to wait for the input/output connection to send an event. We need to include this line in App.js otherwise Node is going to be waiting for something to happen after the code gets executed as long as there is an open socket.&lt;br /&gt;
&lt;br /&gt;
=== App.js ===&lt;br /&gt;
&lt;br /&gt;
The variable &amp;lt;code&amp;gt;mongoStore&amp;lt;/code&amp;gt; declared at:&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; var MongoStore = require(&#039;connect-mongo&#039;)(express);&lt;br /&gt;
&lt;br /&gt;
was used at: &lt;br /&gt;
&lt;br /&gt;
 &amp;gt; app.use(express.session({&lt;br /&gt;
 &amp;gt; cookie: {maxAge: 60000 * 20} // 20 minutes&lt;br /&gt;
 &amp;gt; , secret: &amp;quot;Shh... I&#039;m a secret&amp;quot;&lt;br /&gt;
 &amp;gt; , store: new MongoStore({db: &amp;quot;adventure-demo&amp;quot;})&lt;br /&gt;
 &amp;gt; }));&lt;br /&gt;
&lt;br /&gt;
The piece of code above provides session support and it is there to have cookies used when handling requests from the browser. Without sessions, there is no other way for the web app to know if the player is logged in or not.&lt;br /&gt;
&lt;br /&gt;
The following line specifies how long the cookies last:&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; cookie: {maxAge: 60000 * 20} // 20 minutes&lt;br /&gt;
&lt;br /&gt;
This following line :&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; store: new MongoStore({db: &amp;quot;adventure-demo&amp;quot;})&lt;br /&gt;
&lt;br /&gt;
is saying do not store the session in memory otherwise all sessions will be lost if the server was restarted. It is saying store the session in an instance of mongostore and the database to use is “adventure–demo”.&lt;br /&gt;
&lt;br /&gt;
It is important to note that, in app.js, the web server is being created and it runs first and then the rooms are getting added.&lt;br /&gt;
&lt;br /&gt;
=== Index.js ===&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; playersCollection.find({playername: playername}).toArray(addPlayer);&lt;br /&gt;
&lt;br /&gt;
finds the player collection having the player name similar to the content of the variable &amp;lt;code&amp;gt;playername&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;PlayerCollection.find({playername: playername})&amp;lt;/code&amp;gt; part returns a cursor object and the &amp;lt;code&amp;gt;toArray(addPlayer)&amp;lt;/code&amp;gt; part turns it into an array.&lt;br /&gt;
&lt;br /&gt;
While all static pages that are being served are in the public library, Jade templates are server side dynamic web pages. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Home.js ===&lt;br /&gt;
&lt;br /&gt;
The code in this file runs on the browser so it is a client-side code.&lt;br /&gt;
&lt;br /&gt;
=== Other Important Stuff: ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
• All of the available databases can be shown using the &amp;lt;code&amp;gt;show dbs&amp;lt;/code&amp;gt; mongo shell command (located in our mongodb installation directory and can be started by typing in &amp;lt;code&amp;gt;./bin/mongo&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
• Collections of this database can be shown by typing in &amp;lt;code&amp;gt;use adventure-demo&amp;lt;/code&amp;gt; then &amp;lt;code&amp;gt;show collections&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
• &amp;lt;code&amp;gt;db.sessions.find()&amp;lt;/code&amp;gt; shows the active sessions in the database.&lt;br /&gt;
&lt;br /&gt;
• &amp;lt;code&amp;gt;db.players.drop()&amp;lt;/code&amp;gt; deletes the players collection.&lt;br /&gt;
&lt;br /&gt;
• Note that when we try to access a collection that does not exist, Mongodb creates it.&lt;br /&gt;
&lt;br /&gt;
• Mongodb is not a part of node. It is a completely separate executable. Mongodb works well with node particularly because it uses JavaScript internally.&lt;br /&gt;
&lt;br /&gt;
• Next () is provided by the “connect” middleware and refers to the next middleware in the express stack.&lt;br /&gt;
&lt;br /&gt;
[http://stackoverflow.com/questions/8710669/having-a-hard-time-trying-to-understand-next-next-in-express-js Having a hard time trying to understand &#039;next/next()&#039; in express.js?]&lt;br /&gt;
&lt;br /&gt;
• Callbacks (as explained in an article posted on [http://javascriptissexy.com/understand-javascript-callback-functions-and-use-them/ javascriptissexy.com]):&lt;br /&gt;
&lt;br /&gt;
In JavaScript, functions are first-class objects, which means that they can be “stored in variables, passed as arguments to functions, created within functions, and returned from functions”&lt;br /&gt;
&lt;br /&gt;
A callback function is a function that is passed to another function (let’s call this other function “otherFunction”) as a parameter, and the callback function is called (executed) inside otherFunction.&lt;br /&gt;
&lt;br /&gt;
When we pass a callback function as an argument to another function, we are only passing the function definition. We are not executing the function in the parameter. We aren’t passing the function with the trailing pair of executing parenthesis () like we do when we are executing a function. And since the containing function has the callback function in its parameter as a function definition, it can execute the callback anytime. &lt;br /&gt;
&lt;br /&gt;
It is important to note that the callback function is not executed immediately. It is “called back” (hence the name) at some specified point inside the containing function’s body.&lt;/div&gt;</summary>
		<author><name>Gkadri</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2014W_Lecture_9&amp;diff=18708</id>
		<title>WebFund 2014W Lecture 9</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2014W_Lecture_9&amp;diff=18708"/>
		<updated>2014-03-02T01:52:36Z</updated>

		<summary type="html">&lt;p&gt;Gkadri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The video from the lecture given on February 5, 2014 is available:&lt;br /&gt;
* [http://www.screencast.com/t/W9rewtusggz Small from screencast.com]&lt;br /&gt;
* [http://www.screencast.com/t/cJmYPtR6 Large from screencast.com]&lt;br /&gt;
* [http://dl.cuol.ca/capture/Anil.Somayaji/COMP_2406_2014W_Lecture_9_-_20140205_143924_27.mp4 Original from CUOL]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Lecture Notes ==&lt;br /&gt;
&lt;br /&gt;
In this lecture the adventure-demo app of assignment 2 is explained. &lt;br /&gt;
&lt;br /&gt;
=== storeRooms.js ===&lt;br /&gt;
&lt;br /&gt;
storeRooms.js connects to the database and creates the collection called Rooms. If the collection tables already exist, then it drops it. MongoDb stores the last room the player was at before leaving the game. Even if the server was killed and was started up again, it still remembers the last room of each player.&lt;br /&gt;
&lt;br /&gt;
It is important to note that &amp;lt;code&amp;gt;db.close();&amp;lt;/code&amp;gt; at the end of storeRooms.js terminates the node process. Node is designed to wait for the input/output connection to send an event. We need to include this line in App.js otherwise Node is going to be waiting for something to happen after the code gets executed as long as there is an open socket.&lt;br /&gt;
&lt;br /&gt;
=== App.js ===&lt;br /&gt;
&lt;br /&gt;
The variable &amp;lt;code&amp;gt;mongoStore&amp;lt;/code&amp;gt; declared at:&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; var MongoStore = require(&#039;connect-mongo&#039;)(express);&lt;br /&gt;
&lt;br /&gt;
was used at: &lt;br /&gt;
&lt;br /&gt;
 &amp;gt; app.use(express.session({&lt;br /&gt;
 &amp;gt; cookie: {maxAge: 60000 * 20} // 20 minutes&lt;br /&gt;
 &amp;gt; , secret: &amp;quot;Shh... I&#039;m a secret&amp;quot;&lt;br /&gt;
 &amp;gt; , store: new MongoStore({db: &amp;quot;adventure-demo&amp;quot;})&lt;br /&gt;
 &amp;gt; }));&lt;br /&gt;
&lt;br /&gt;
The piece of code above provides session support and it is there to have cookies used when handling requests from the browser. Without sessions, there is no other way for the web app to know if the player is logged in or not.&lt;br /&gt;
&lt;br /&gt;
The following line specifies how long the cookies last:&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; cookie: {maxAge: 60000 * 20} // 20 minutes&lt;br /&gt;
&lt;br /&gt;
This following line :&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; store: new MongoStore({db: &amp;quot;adventure-demo&amp;quot;})&lt;br /&gt;
&lt;br /&gt;
is saying do not store the session in memory otherwise all sessions will be lost if the server was restarted. It is saying store the session in an instance of mongostore and the database to use is “adventure–demo”.&lt;br /&gt;
&lt;br /&gt;
It is important to note that, in app.js, the web server is being created and run first and then the rooms are getting added.&lt;br /&gt;
&lt;br /&gt;
=== Index.js ===&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; playersCollection.find({playername: playername}).toArray(addPlayer);&lt;br /&gt;
&lt;br /&gt;
finds the player collection having the player name similar to the content of the variable &amp;lt;code&amp;gt;playername&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;PlayerCollection.find({playername: playername})&amp;lt;/code&amp;gt; part returns a cursor object and the &amp;lt;code&amp;gt;toArray(addPlayer)&amp;lt;/code&amp;gt; part turns it into an array.&lt;br /&gt;
&lt;br /&gt;
While static pages that are being served are all in the public library, Jade templates are server side dynamic web pages. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Home.js ===&lt;br /&gt;
&lt;br /&gt;
The code in this file runs on the browser so it is a client-side code.&lt;br /&gt;
&lt;br /&gt;
=== Other Important Stuff: ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
• All of the available databases can be shown using the &amp;lt;code&amp;gt;show dbs&amp;lt;/code&amp;gt; mongo shell command (located in our mongodb installation directory and can be started by typing &amp;lt;code&amp;gt;./bin/mongo&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
• Collections of this database can be shown by typing in &amp;lt;code&amp;gt;use adventure-demo&amp;lt;/code&amp;gt; then &amp;lt;code&amp;gt;show collections&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
• &amp;lt;code&amp;gt;db.sessions.find()&amp;lt;/code&amp;gt; shows the active sessions in the database.&lt;br /&gt;
&lt;br /&gt;
• &amp;lt;code&amp;gt;db.players.drop()&amp;lt;/code&amp;gt; deletes the players collection.&lt;br /&gt;
&lt;br /&gt;
• Note that when we try to access a collection that does not exist, Mongodb creates it.&lt;br /&gt;
&lt;br /&gt;
• Mongodb is not a part of node. It is a completely separate executable. Mongodb works well with node particularly because it uses JavaScript internally.&lt;br /&gt;
• Next () is provided by the “connect” middleware and refers to the next middleware in the express stack.&lt;br /&gt;
&lt;br /&gt;
[http://stackoverflow.com/questions/8710669/having-a-hard-time-trying-to-understand-next-next-in-express-js Having a hard time trying to understand &#039;next/next()&#039; in express.js?]&lt;br /&gt;
&lt;br /&gt;
• Callbacks (as explained in an article posted on [http://javascriptissexy.com/understand-javascript-callback-functions-and-use-them/ javascriptissexy.com]):&lt;br /&gt;
&lt;br /&gt;
In JavaScript, functions are first-class objects, which means that they can be “stored in variables, passed as arguments to functions, created within functions, and returned from functions”&lt;br /&gt;
&lt;br /&gt;
A callback function is a function that is passed to another function (let’s call this other function “otherFunction”) as a parameter, and the callback function is called (executed) inside otherFunction.&lt;br /&gt;
&lt;br /&gt;
When we pass a callback function as an argument to another function, we are only passing the function definition. We are not executing the function in the parameter. We aren’t passing the function with the trailing pair of executing parenthesis () like we do when we are executing a function. And since the containing function has the callback function in its parameter as a function definition, it can execute the callback anytime. &lt;br /&gt;
&lt;br /&gt;
It is important to note that the callback function is not executed immediately. It is “called back” (hence the name) at some specified point inside the containing function’s body.&lt;/div&gt;</summary>
		<author><name>Gkadri</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2014W_Lecture_5&amp;diff=18555</id>
		<title>WebFund 2014W Lecture 5</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2014W_Lecture_5&amp;diff=18555"/>
		<updated>2014-02-04T23:30:28Z</updated>

		<summary type="html">&lt;p&gt;Gkadri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Video from the lecture given on Jan 22, 2014 is now available from multiple sources:&lt;br /&gt;
* [http://www.screencast.com/t/Aypl5x4M small at screencast.com] (flash/mp4)&lt;br /&gt;
* [http://www.screencast.com/t/gykjMNBv8c large at screencast.com] (flash/mp4)&lt;br /&gt;
* [http://dl.cuol.ca/capture/Anil.Somayaji/COMP_2406_2014W_Lecture_5_-_20140122_151202_27.mp4 original at CUOL] (mp4)&lt;br /&gt;
* [http://homeostasis.scs.carleton.ca/~soma/webfund-2014w/lectures/comp2406-2013f-lec05-22Jan2014.mp4 original at homeostasis] (mp4)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
•	To create an empty object we use:&lt;br /&gt;
&lt;br /&gt;
  o	Var car = { speed: “slow”};&lt;br /&gt;
  o	Var tesla = object.create(car);&lt;br /&gt;
•	To check the properties of the object:&lt;br /&gt;
  o	Tesla.speed&lt;br /&gt;
  o	‘slow’&lt;br /&gt;
•	To assign a different value to the speed property:&lt;br /&gt;
  o	Tesla.speed  = “fast”;&lt;br /&gt;
  o	‘fast’&lt;br /&gt;
•	To assign a default value to a prototype object property:&lt;br /&gt;
  o	Car.colour = “white”;&lt;br /&gt;
  o	‘white’&lt;br /&gt;
•	To check:&lt;br /&gt;
  o	Car&lt;br /&gt;
  o	{ speed: ‘slow’,  colour: ‘white’ }&lt;br /&gt;
  o	Tesla&lt;br /&gt;
  o	{ speed:  ‘fast’ }&lt;br /&gt;
•	Note that the object “tesla” does not have the property colour but its prototype has it.&lt;br /&gt;
  o	Object.getPrototypeOf(tesla);&lt;br /&gt;
  o	{ speed:  ‘slow’,&lt;br /&gt;
  o	colour: ‘white’&lt;br /&gt;
  o	wheels: 4 }&lt;br /&gt;
•	Every object in JavaScript has a prototype that can be accessed by:&lt;br /&gt;
  o	Object.prototype&lt;br /&gt;
•	Session-demo:&lt;br /&gt;
•	Different users have different sessions and the server knows about the different sessions. The server is keeping track of state per user that is logged in.&lt;br /&gt;
&lt;br /&gt;
•	The state is a representation of what is on the server but it is also a reflection of which session has been identified to the server.&lt;br /&gt;
&lt;br /&gt;
•	HTTP is a stateless protocol. Stateless means that each request that goes to the browser is independent of every other request. &lt;br /&gt;
&lt;br /&gt;
•	When you make a request, your browser does not only send URL. It also sends a request with a lot of other properties. This is also a part of the HTTP protocol.(Look under the “Header” tab of the “Network” section in the Firefox console).&lt;br /&gt;
&lt;br /&gt;
•	A User-Agent string is a part of the HTTP request. It is supposed to tell the server what kind of browser you are using. &lt;br /&gt;
&lt;br /&gt;
•	A cookie is some bit of data that is sent somewhere and is expect to be returned later and is not to be processed or “eaten” by the other side.&lt;br /&gt;
&lt;br /&gt;
•	Status code: every HTTP request that comes in to a server will generate a response code. (i.e. response code 200 means o.k. Response code 404 means page not found and 302 means page moved temporarily).&lt;br /&gt;
&lt;br /&gt;
•	Node is a general web application execution platform. Express is a framework for it. &lt;br /&gt;
&lt;br /&gt;
•	The following function takes ‘Comp 4106 rules!’ as a secret argument to encrypt the user session and to generate the valid cookies. The cookies must be made to be hard to reverse by others.&lt;br /&gt;
  o	app.use(express.cookieParser(‘Comp 2406 rules!’));&lt;br /&gt;
•	The following function uses the cookie parser in order to maintain sessions. It is the session identifier. Every time we do a “get” a cookies comes along with it and the user is identified:&lt;br /&gt;
  o	app.use(express.session());&lt;br /&gt;
•	Cookies can be specified with different life times. Some cookies  are specified with session only life time. Some other cookies are specified to live for hours, days or years.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
•	/routes/Index.js:&lt;br /&gt;
&lt;br /&gt;
•	When the user enters the username, the incoming request has a session sub-object which is defined by the session layer of Express&lt;br /&gt;
&lt;br /&gt;
•	If the session object has a username as a property, the user is already logged in&lt;br /&gt;
&lt;br /&gt;
  o	Function index (req, res) {&lt;br /&gt;
  o	If (req.session.username){&lt;br /&gt;
  o	     res.redirect(“/users”);&lt;br /&gt;
  o	} else {&lt;br /&gt;
  o	res.render(‘index’), { title: ‘COMP 2406 Session Demo’,&lt;br /&gt;
  o	                                   error: req.query.error  });&lt;br /&gt;
  o	}&lt;br /&gt;
  o	}&lt;br /&gt;
&lt;br /&gt;
•	In the following code we set the username variable by (req.session.username)&lt;br /&gt;
&lt;br /&gt;
  o	Function login (req, res) {&lt;br /&gt;
  o	Var username = req.body.username;&lt;br /&gt;
  o	Req.session.username = username;&lt;br /&gt;
  o	loggedInUsers [username] = LoggedIn;&lt;br /&gt;
  o	res.redirect (“/users”)&lt;br /&gt;
  o	}&lt;br /&gt;
&lt;br /&gt;
•	Note that the user name came from the req.body object.&lt;br /&gt;
&lt;br /&gt;
•	(req.body.username) is a part of the form.&lt;br /&gt;
&lt;br /&gt;
•	The form “post” sends the user name to the server (this can be viewed under the “params” tab of the “network” section in the console.&lt;br /&gt;
&lt;br /&gt;
•	Next we save it to the session by  &lt;br /&gt;
  o	Req.session.username = username;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
•	When you ever see a line like:&lt;br /&gt;
  o	Form (action=”/login” , method=”post”)&lt;br /&gt;
&lt;br /&gt;
In /views/index.jade&lt;br /&gt;
You should expect to see a corresponding route like:&lt;br /&gt;
  o	App.post(“/login”, routes.login);&lt;br /&gt;
  o	App.post(“/logout”, routes.logout)&lt;br /&gt;
In app.js&lt;br /&gt;
Otherwise there will be a 404 error (page not found).&lt;br /&gt;
&lt;br /&gt;
•	When deleting &lt;br /&gt;
  o	App.use(express.json());&lt;br /&gt;
Nothing really happens&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
•	When deleting&lt;br /&gt;
  o	App.use(express.urlencoded());&lt;br /&gt;
The (req.session.username) condition in index.js (as shown below) fails and it won’t consider the user logged in.&lt;br /&gt;
  o	Function users (req, res) {&lt;br /&gt;
  o		If(req.session.username){&lt;br /&gt;
  o			res/render (“account.jade”, {username: req.session.username,&lt;br /&gt;
  o	title:”Account”,&lt;br /&gt;
  o	loggedInUsers: loggedInUsers});&lt;br /&gt;
  o	} else {&lt;br /&gt;
  o			res.redirect(“/?error=Not Logged In”);&lt;br /&gt;
  o	}&lt;br /&gt;
  o	};&lt;/div&gt;</summary>
		<author><name>Gkadri</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2014W_Lecture_5&amp;diff=18554</id>
		<title>WebFund 2014W Lecture 5</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2014W_Lecture_5&amp;diff=18554"/>
		<updated>2014-02-04T23:29:23Z</updated>

		<summary type="html">&lt;p&gt;Gkadri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Video from the lecture given on Jan 22, 2014 is now available from multiple sources:&lt;br /&gt;
* [http://www.screencast.com/t/Aypl5x4M small at screencast.com] (flash/mp4)&lt;br /&gt;
* [http://www.screencast.com/t/gykjMNBv8c large at screencast.com] (flash/mp4)&lt;br /&gt;
* [http://dl.cuol.ca/capture/Anil.Somayaji/COMP_2406_2014W_Lecture_5_-_20140122_151202_27.mp4 original at CUOL] (mp4)&lt;br /&gt;
* [http://homeostasis.scs.carleton.ca/~soma/webfund-2014w/lectures/comp2406-2013f-lec05-22Jan2014.mp4 original at homeostasis] (mp4)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
•	To create an empty object we use:&lt;br /&gt;
&lt;br /&gt;
  o	Var car = { speed: “slow”};&lt;br /&gt;
  o	Var tesla = object.create(car);&lt;br /&gt;
•	To check the properties of the object:&lt;br /&gt;
  o	Tesla.speed&lt;br /&gt;
  o	‘slow’&lt;br /&gt;
•	To assign a different value to the speed property:&lt;br /&gt;
  o	Tesla.speed  = “fast”;&lt;br /&gt;
  o	‘fast’&lt;br /&gt;
•	To assign a default value to a prototype object property:&lt;br /&gt;
  o	Car.colour = “white”;&lt;br /&gt;
  o	‘white’&lt;br /&gt;
•	To check:&lt;br /&gt;
  o	Car&lt;br /&gt;
  o	{ speed: ‘slow’,  colour: ‘white’ }&lt;br /&gt;
  o	Tesla&lt;br /&gt;
  o	{ speed:  ‘fast’ }&lt;br /&gt;
•	Note that the object “tesla” does not have the property colour but its prototype has it.&lt;br /&gt;
  o	Object.getPrototypeOf(tesla);&lt;br /&gt;
  o	{ speed:  ‘slow’,&lt;br /&gt;
  o	colour: ‘white’&lt;br /&gt;
  o	wheels: 4 }&lt;br /&gt;
•	Every object in JavaScript has a prototype that can be accessed by:&lt;br /&gt;
  o	Object.prototype&lt;br /&gt;
•	Session-demo:&lt;br /&gt;
•	Different users have different sessions and the server knows about the different sessions. The server is keeping track of state per user that is logged in.&lt;br /&gt;
•	The state is a representation of what is on the server but it is also a reflection of which session has been identified to the server.&lt;br /&gt;
•	HTTP is a stateless protocol. Stateless means that each request that goes to the browser is independent of every other request. &lt;br /&gt;
•	When you make a request, your browser does not only send URL. It also sends a request with a lot of other properties. This is also a part of the HTTP protocol.(Look under the “Header” tab of the “Network” section in the Firefox console).&lt;br /&gt;
&lt;br /&gt;
•	A User-Agent string is a part of the HTTP request. It is supposed to tell the server what kind of browser you are using. &lt;br /&gt;
•	A cookie is some bit of data that is sent somewhere and is expect to be returned later and is not to be processed or “eaten” by the other side.&lt;br /&gt;
•	Status code: every HTTP request that comes in to a server will generate a response code. (i.e. response code 200 means o.k. Response code 404 means page not found and 302 means page moved temporarily).&lt;br /&gt;
•	Node is a general web application execution platform. Express is a framework for it. &lt;br /&gt;
•	The following function takes ‘Comp 4106 rules!’ as a secret argument to encrypt the user session and to generate the valid cookies. The cookies must be made to be hard to reverse by others.&lt;br /&gt;
  o	app.use(express.cookieParser(‘Comp 2406 rules!’));&lt;br /&gt;
•	The following function uses the cookie parser in order to maintain sessions. It is the session identifier. Every time we do a “get” a cookies comes along with it and the user is identified:&lt;br /&gt;
  o	app.use(express.session());&lt;br /&gt;
•	Cookies can be specified with different life times. Some cookies  are specified with session only life time. Some other cookies are specified to live for hours, days or years.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
•	/routes/Index.js:&lt;br /&gt;
•	When the user enters the username, the incoming request has a session sub-object which is defined by the session layer of Express&lt;br /&gt;
•	If the session object has a username as a property, the user is already logged in&lt;br /&gt;
&lt;br /&gt;
  o	Function index (req, res) {&lt;br /&gt;
  o	If (req.session.username){&lt;br /&gt;
  o	     res.redirect(“/users”);&lt;br /&gt;
  o	} else {&lt;br /&gt;
  o	res.render(‘index’), { title: ‘COMP 2406 Session Demo’,&lt;br /&gt;
  o	                                   error: req.query.error  });&lt;br /&gt;
  o	}&lt;br /&gt;
  o	}&lt;br /&gt;
&lt;br /&gt;
•	In the following code we set the username variable by (req.session.username)&lt;br /&gt;
&lt;br /&gt;
  o	Function login (req, res) {&lt;br /&gt;
  o	Var username = req.body.username;&lt;br /&gt;
  o	Req.session.username = username;&lt;br /&gt;
  o	loggedInUsers [username] = LoggedIn;&lt;br /&gt;
  o	res.redirect (“/users”)&lt;br /&gt;
  o	}&lt;br /&gt;
&lt;br /&gt;
•	Note that the user name came from the req.body object.&lt;br /&gt;
•	(req.body.username) is a part of the form.&lt;br /&gt;
•	The form “post” sends the user name to the server (this can be viewed under the “params” tab of the “network” section in the console.&lt;br /&gt;
•	Next we save it to the session by  &lt;br /&gt;
  o	Req.session.username = username;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
•	When you ever see a line like:&lt;br /&gt;
  o	Form (action=”/login” , method=”post”)&lt;br /&gt;
&lt;br /&gt;
In /views/index.jade&lt;br /&gt;
You should expect to see a corresponding route like:&lt;br /&gt;
  o	App.post(“/login”, routes.login);&lt;br /&gt;
  o	App.post(“/logout”, routes.logout)&lt;br /&gt;
In app.js&lt;br /&gt;
Otherwise there will be a 404 error (page not found).&lt;br /&gt;
&lt;br /&gt;
•	When deleting &lt;br /&gt;
  o	App.use(express.json());&lt;br /&gt;
Nothing really happens&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
•	When deleting&lt;br /&gt;
  o	App.use(express.urlencoded());&lt;br /&gt;
The (req.session.username) condition in index.js (as shown below) fails and it won’t consider the user logged in.&lt;br /&gt;
  o	Function users (req, res) {&lt;br /&gt;
  o		If(req.session.username){&lt;br /&gt;
  o			res/render (“account.jade”, {username: req.session.username,&lt;br /&gt;
  o	title:”Account”,&lt;br /&gt;
  o	loggedInUsers: loggedInUsers});&lt;br /&gt;
  o	} else {&lt;br /&gt;
  o			res.redirect(“/?error=Not Logged In”);&lt;br /&gt;
  o	}&lt;br /&gt;
  o	};&lt;/div&gt;</summary>
		<author><name>Gkadri</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2014W_Lecture_5&amp;diff=18553</id>
		<title>WebFund 2014W Lecture 5</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2014W_Lecture_5&amp;diff=18553"/>
		<updated>2014-02-04T23:28:58Z</updated>

		<summary type="html">&lt;p&gt;Gkadri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Video from the lecture given on Jan 22, 2014 is now available from multiple sources:&lt;br /&gt;
* [http://www.screencast.com/t/Aypl5x4M small at screencast.com] (flash/mp4)&lt;br /&gt;
* [http://www.screencast.com/t/gykjMNBv8c large at screencast.com] (flash/mp4)&lt;br /&gt;
* [http://dl.cuol.ca/capture/Anil.Somayaji/COMP_2406_2014W_Lecture_5_-_20140122_151202_27.mp4 original at CUOL] (mp4)&lt;br /&gt;
* [http://homeostasis.scs.carleton.ca/~soma/webfund-2014w/lectures/comp2406-2013f-lec05-22Jan2014.mp4 original at homeostasis] (mp4)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
•	To create an empty object we use:&lt;br /&gt;
&lt;br /&gt;
  o	Var car = { speed: “slow”};&lt;br /&gt;
  o	Var tesla = object.create(car);&lt;br /&gt;
•	To check the properties of the object:&lt;br /&gt;
  o	Tesla.speed&lt;br /&gt;
  o	‘slow’&lt;br /&gt;
•	To assign a different value to the speed property:&lt;br /&gt;
  o	Tesla.speed  = “fast”;&lt;br /&gt;
  o	‘fast’&lt;br /&gt;
•	To assign a default value to a prototype object property:&lt;br /&gt;
  o	Car.colour = “white”;&lt;br /&gt;
  o	‘white’&lt;br /&gt;
•	To check:&lt;br /&gt;
  o	Car&lt;br /&gt;
  o	{ speed: ‘slow’,  colour: ‘white’ }&lt;br /&gt;
  o	Tesla&lt;br /&gt;
  o	{ speed:  ‘fast’ }&lt;br /&gt;
•	Note that the object “tesla” does not have the property colour but its prototype has it.&lt;br /&gt;
  o	Object.getPrototypeOf(tesla);&lt;br /&gt;
  o	{ speed:  ‘slow’,&lt;br /&gt;
  o	colour: ‘white’&lt;br /&gt;
  o	wheels: 4 }&lt;br /&gt;
•	Every object in JavaScript has a prototype that can be accessed by:&lt;br /&gt;
  o	Object.prototype&lt;br /&gt;
•	Session-demo:&lt;br /&gt;
•	Different users have different sessions and the server knows about the different sessions. The server is keeping track of state per user that is logged in.&lt;br /&gt;
•	The state is a representation of what is on the server but it is also a reflection of which session has been identified to the server.&lt;br /&gt;
•	HTTP is a stateless protocol. Stateless means that each request that goes to the browser is independent of every other request. &lt;br /&gt;
•	When you make a request, your browser does not only send URL. It also sends a request with a lot of other properties. This is also a part of the HTTP protocol.(Look under the “Header” tab of the “Network” section in the Firefox console).&lt;br /&gt;
&lt;br /&gt;
•	A User-Agent string is a part of the HTTP request. It is supposed to tell the server what kind of browser you are using. &lt;br /&gt;
•	A cookie is some bit of data that is sent somewhere and is expect to be returned later and is not to be processed or “eaten” by the other side.&lt;br /&gt;
•	Status code: every HTTP request that comes in to a server will generate a response code. (i.e. response code 200 means o.k. Response code 404 means page not found and 302 means page moved temporarily).&lt;br /&gt;
•	Node is a general web application execution platform. Express is a framework for it. &lt;br /&gt;
•	The following function takes ‘Comp 4106 rules!’ as a secret argument to encrypt the user session and to generate the valid cookies. The cookies must be made to be hard to reverse by others.&lt;br /&gt;
  o	app.use(express.cookieParser(‘Comp 2406 rules!’));&lt;br /&gt;
•	The following function uses the cookie parser in order to maintain sessions. It is the session identifier. Every time we do a “get” a cookies comes along with it and the user is identified:&lt;br /&gt;
  o	app.use(express.session());&lt;br /&gt;
•	Cookies can be specified with different life times. Some cookies  are specified with session only life time. Some other cookies are specified to live for hours, days or years.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
•	/routes/Index.js:&lt;br /&gt;
•	When the user enters the username, the incoming request has a session sub-object which is defined by the session layer of Express&lt;br /&gt;
•	If the session object has a username as a property, the user is already logged in&lt;br /&gt;
&lt;br /&gt;
  o	Function index (req, res) {&lt;br /&gt;
  o	If (req.session.username){&lt;br /&gt;
  o	     res.redirect(“/users”);&lt;br /&gt;
  o	} else {&lt;br /&gt;
  o	res.render(‘index’), { title: ‘COMP 2406 Session Demo’,&lt;br /&gt;
  o	                                   error: req.query.error  });&lt;br /&gt;
  o	}&lt;br /&gt;
  o	}&lt;br /&gt;
&lt;br /&gt;
•	In the following code we set the username variable by (req.session.username)&lt;br /&gt;
&lt;br /&gt;
  o	Function login (req, res) {&lt;br /&gt;
  o	Var username = req.body.username;&lt;br /&gt;
  o	Req.session.username = username;&lt;br /&gt;
  o	loggedInUsers [username] = LoggedIn;&lt;br /&gt;
  o	res.redirect (“/users”)&lt;br /&gt;
  o	}&lt;br /&gt;
&lt;br /&gt;
•	Note that the user name came from the req.body object.&lt;br /&gt;
•	(req.body.username) is a part of the form.&lt;br /&gt;
•	The form “post” sends the user name to the server (this can be viewed under the “params” tab of the “network” section in the console.&lt;br /&gt;
•	Next we save it to the session by  &lt;br /&gt;
  o	Req.session.username = username;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
•	When you ever see a line like:&lt;br /&gt;
  o	Form (action=”/login” , method=”post”)&lt;br /&gt;
&lt;br /&gt;
In /views/index.jade&lt;br /&gt;
You should expect to see a corresponding route like:&lt;br /&gt;
  o	App.post(“/login”, routes.login);&lt;br /&gt;
  o	App.post(“/logout”, routes.logout)&lt;br /&gt;
In app.js&lt;br /&gt;
Otherwise there will be a 404 error (page not found).&lt;br /&gt;
&lt;br /&gt;
•	When deleting &lt;br /&gt;
  o	App.use(express.json());&lt;br /&gt;
Nothing really happens&lt;br /&gt;
•	When deleting&lt;br /&gt;
  o	App.use(express.urlencoded());&lt;br /&gt;
The (req.session.username) condition in index.js (as shown below) fails and it won’t consider the user logged in.&lt;br /&gt;
  o	Function users (req, res) {&lt;br /&gt;
  o		If(req.session.username){&lt;br /&gt;
  o			res/render (“account.jade”, {username: req.session.username,&lt;br /&gt;
  o	title:”Account”,&lt;br /&gt;
  o	loggedInUsers: loggedInUsers});&lt;br /&gt;
  o	} else {&lt;br /&gt;
  o			res.redirect(“/?error=Not Logged In”);&lt;br /&gt;
  o	}&lt;br /&gt;
  o	};&lt;/div&gt;</summary>
		<author><name>Gkadri</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2014W_Lecture_5&amp;diff=18552</id>
		<title>WebFund 2014W Lecture 5</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2014W_Lecture_5&amp;diff=18552"/>
		<updated>2014-02-04T23:26:47Z</updated>

		<summary type="html">&lt;p&gt;Gkadri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Video from the lecture given on Jan 22, 2014 is now available from multiple sources:&lt;br /&gt;
* [http://www.screencast.com/t/Aypl5x4M small at screencast.com] (flash/mp4)&lt;br /&gt;
* [http://www.screencast.com/t/gykjMNBv8c large at screencast.com] (flash/mp4)&lt;br /&gt;
* [http://dl.cuol.ca/capture/Anil.Somayaji/COMP_2406_2014W_Lecture_5_-_20140122_151202_27.mp4 original at CUOL] (mp4)&lt;br /&gt;
* [http://homeostasis.scs.carleton.ca/~soma/webfund-2014w/lectures/comp2406-2013f-lec05-22Jan2014.mp4 original at homeostasis] (mp4)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
•	To create an empty object we use:&lt;br /&gt;
&lt;br /&gt;
  o	Var car = { speed: “slow”};&lt;br /&gt;
  o	Var tesla = object.create(car);&lt;br /&gt;
•	To check the properties of the object:&lt;br /&gt;
  o	Tesla.speed&lt;br /&gt;
  o	‘slow’&lt;br /&gt;
•	To assign a different value to the speed property:&lt;br /&gt;
  o	Tesla.speed  = “fast”;&lt;br /&gt;
  o	‘fast’&lt;br /&gt;
•	To assign a default value to a prototype object property:&lt;br /&gt;
  o	Car.colour = “white”;&lt;br /&gt;
  o	‘white’&lt;br /&gt;
•	To check:&lt;br /&gt;
  o	Car&lt;br /&gt;
  o	{ speed: ‘slow’,  colour: ‘white’ }&lt;br /&gt;
  o	Tesla&lt;br /&gt;
  o	{ speed:  ‘fast’ }&lt;br /&gt;
•	Note that the object “tesla” does not have the property colour but its prototype has it.&lt;br /&gt;
  o	Object.getPrototypeOf(tesla);&lt;br /&gt;
  o	{ speed:  ‘slow’,&lt;br /&gt;
  o	colour: ‘white’&lt;br /&gt;
  o	wheels: 4 }&lt;br /&gt;
•	Every object in JavaScript has a prototype that can be accessed by:&lt;br /&gt;
  o	Object.prototype&lt;br /&gt;
•	Session-demo:&lt;br /&gt;
•	Different users have different sessions and the server knows about the different sessions. The server is keeping track of state per user that is logged in.&lt;br /&gt;
•	The state is representation of what is on the server but it is also a reflection of which session has been identified to the server.&lt;br /&gt;
•	HTTP is a stateless protocol. Stateless means that each request that goes to the browser is independent of every other request. &lt;br /&gt;
•	When you make a request, your browser does not only send URL. It also sends a request with a lot of other properties. This is also a part of the HTTP protocol.(Look under the “Header” tab of the “Network” section in the Firefox console).&lt;br /&gt;
&lt;br /&gt;
•	A User-Agent string is a part of the HTTP request. It is supposed to tell the server what kind of browser you are using. &lt;br /&gt;
•	A cookie is some bit of data that is sent somewhere and is expect to be returned later and is not to be processed or “eaten” by the other side.&lt;br /&gt;
•	Status code: every HTTP request that comes in to a server will generate a response code. (i.e. response code 200 means o.k. Response code 404 means page not found and 302 means page moved temporarily).&lt;br /&gt;
•	Node is a general web application execution platform. Express is a framework for it. &lt;br /&gt;
•	The following function takes ‘Comp 4106 rules!’ as a secret argument to encrypt the user session and to generate the valid cookies. The cookies must be made to be hard to reverse by others.&lt;br /&gt;
  o	app.use(express.cookieParser(‘Comp 2406 rules!’));&lt;br /&gt;
•	The following function uses the cookie parser in order to maintain sessions. It is the session identifier. Every time we do a “get” a cookies comes along with it and the user is identified:&lt;br /&gt;
  o	app.use(express.session());&lt;br /&gt;
•	Cookies can be specified with different life times. Some cookies  are specified with session only life time. Some other cookies are specified to live for hours, days or years.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
•	/routes/Index.js:&lt;br /&gt;
•	When the user enters the username, the incoming request has a session sub-object which is defined by the session layer of Express&lt;br /&gt;
•	If the session object has a username as a property, the user is already logged in&lt;br /&gt;
&lt;br /&gt;
  o	Function index (req, res) {&lt;br /&gt;
  o	If (req.session.username){&lt;br /&gt;
  o	     res.redirect(“/users”);&lt;br /&gt;
  o	} else {&lt;br /&gt;
  o	res.render(‘index’), { title: ‘COMP 2406 Session Demo’,&lt;br /&gt;
  o	                                   error: req.query.error  });&lt;br /&gt;
  o	}&lt;br /&gt;
  o	}&lt;br /&gt;
&lt;br /&gt;
•	In the following code we set the username variable by (req.session.username)&lt;br /&gt;
&lt;br /&gt;
  o	Function login (req, res) {&lt;br /&gt;
  o	Var username = req.body.username;&lt;br /&gt;
  o	Req.session.username = username;&lt;br /&gt;
  o	loggedInUsers [username] = LoggedIn;&lt;br /&gt;
  o	res.redirect (“/users”)&lt;br /&gt;
  o	}&lt;br /&gt;
&lt;br /&gt;
•	Note that the user name came from the req.body object.&lt;br /&gt;
•	(req.body.username) is a part of the form.&lt;br /&gt;
•	The form “post” sends the user name to the server (this can be viewed under the “params” tab of the “network” section in the console.&lt;br /&gt;
•	Next we save it to the session by  &lt;br /&gt;
  o	Req.session.username = username;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
•	When you ever see a line like:&lt;br /&gt;
  o	Form (action=”/login” , method=”post”)&lt;br /&gt;
&lt;br /&gt;
In /views/index.jade&lt;br /&gt;
You should expect to see a corresponding route like:&lt;br /&gt;
  o	App.post(“/login”, routes.login);&lt;br /&gt;
  o	App.post(“/logout”, routes.logout)&lt;br /&gt;
In app.js&lt;br /&gt;
Otherwise there will be a 404 error (page not found).&lt;br /&gt;
&lt;br /&gt;
•	When deleting &lt;br /&gt;
  o	App.use(express.json());&lt;br /&gt;
Nothing really happens&lt;br /&gt;
•	When deleting&lt;br /&gt;
  o	App.use(express.urlencoded());&lt;br /&gt;
The (req.session.username) condition in index.js (as shown below) fails and it won’t consider the user logged in.&lt;br /&gt;
  o	Function users (req, res) {&lt;br /&gt;
  o		If(req.session.username){&lt;br /&gt;
  o			res/render (“account.jade”, {username: req.session.username,&lt;br /&gt;
  o	title:”Account”,&lt;br /&gt;
  o	loggedInUsers: loggedInUsers});&lt;br /&gt;
  o	} else {&lt;br /&gt;
  o			res.redirect(“/?error=Not Logged In”);&lt;br /&gt;
  o	}&lt;br /&gt;
  o	};&lt;/div&gt;</summary>
		<author><name>Gkadri</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2014W_Lecture_3&amp;diff=18448</id>
		<title>WebFund 2014W Lecture 3</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=WebFund_2014W_Lecture_3&amp;diff=18448"/>
		<updated>2014-01-20T02:39:33Z</updated>

		<summary type="html">&lt;p&gt;Gkadri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The audio from the lecture given on January 15, 2014 is available [http://homeostasis.scs.carleton.ca/~soma/webfund-2014w/lectures/comp2406-2013f-lec03-15Jan2014.mp3 here].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
&lt;br /&gt;
- Node is a JavaScript-based web application whose running times is based on Chrome V8 engine.&lt;br /&gt;
&lt;br /&gt;
- What is JavaScript as an environment?&lt;br /&gt;
&lt;br /&gt;
- How does it compare to a system running C or C++? What’s the key difference?&lt;br /&gt;
&lt;br /&gt;
- Assembler, C, C++ (these need more programming time but less run time)&lt;br /&gt;
&lt;br /&gt;
- Python, Java, Ruby, JavaScript, LISP (these need less programming time but more run time)&lt;br /&gt;
&lt;br /&gt;
- Rule of Thumb: 90% of your run time may be taken by 10% of your code.&lt;br /&gt;
&lt;br /&gt;
- Intel and AMD don’t only produce new processors but they also benchmark them expensively on real world programs.&lt;br /&gt;
&lt;br /&gt;
- Engineers don’t usually know how much time new processors take to run certain programs until they actually test them.&lt;br /&gt;
&lt;br /&gt;
- A CPU optimizes hotspots in programs continuously but not statically.&lt;br /&gt;
&lt;br /&gt;
- JavaScript is a garbage collecting language (like java) but it is not like java in one key respective that JavaScript is a loosely typed language while Java is a strongly typed language.&lt;br /&gt;
&lt;br /&gt;
- JavaScript does not have classes because it does not associate types with symbols (A symbol is just a reference to any kind of data). In JavaScript, even a code is referred to as data.&lt;br /&gt;
&lt;br /&gt;
- The answer of X/Y depends on the type of X &amp;amp; Y.&lt;br /&gt;
&lt;br /&gt;
- All numbers in JavaScript are doubles.&lt;br /&gt;
&lt;br /&gt;
- “Eval” function is a magical function because it takes a string of input and it runs it (or it evaluates it).&lt;br /&gt;
&lt;br /&gt;
- In JavaScript there are global variables, local variables and nested functions.&lt;br /&gt;
&lt;br /&gt;
- When you start using functions, all of your intuition gets messed up.&lt;br /&gt;
&lt;br /&gt;
- In JavaScript lexical scoping encompasses dynamic scoping.&lt;br /&gt;
&lt;br /&gt;
- In JavaScript, functions are data so we can return them from other functions.&lt;br /&gt;
&lt;br /&gt;
- Having functions returning functions is a common design pattern in JavaScript.&lt;br /&gt;
&lt;br /&gt;
- In JavaScript, “undefined” is a specific symbol value.&lt;br /&gt;
&lt;br /&gt;
- In other languages, when we try to access something undefined we get run-time error or compile-time error. In JavaScript, we don’t get an error but we get the value “undefined”.&lt;br /&gt;
-In JavaScript there are no classes but there objects.&lt;br /&gt;
&lt;br /&gt;
- In JavaScript, the purpose of a class is to tell how an object looks like. JavaScript is an object-oriented language&lt;br /&gt;
- Objects in JavaScript are thought of as associative arrays.&lt;br /&gt;
&lt;br /&gt;
- Arrays are indexed by values. Associative arrays are indexed by strings. Hashing the strings gives the offset and the value.&lt;br /&gt;
-JavaScript is LISP like language.&lt;br /&gt;
&lt;br /&gt;
- In JavaScript, inheritance is based on prototypes. The idea of prototypes is when we try to access a property of an object that is not actually defined in the object and we just get back the value of “undefined”. This is not actually how it works. This is what happens when we can’t find any value of it, but it will actually look at a chain of objects. It will specifically look for the property type of the object and it will assume that the prototype refers to another object and that object will be then used to read after that.&lt;br /&gt;
&lt;br /&gt;
- “Require“ takes a file and loads it and evaluates it and then it takes the export object that was in that file and it returns it as its return value.&lt;br /&gt;
&lt;br /&gt;
- Express.static is an apache static file web server.&lt;br /&gt;
&lt;br /&gt;
- Everything in /public should  be accessible by the regular web page.&lt;br /&gt;
&lt;br /&gt;
- Two places to look for JavaScript: Server and kernel.&lt;/div&gt;</summary>
		<author><name>Gkadri</name></author>
	</entry>
</feed>