Node 2 hour course
Agenda
-
0:00 - 0:05 Course Outline
-
0:05 - 0:30 Discussion - What Is Node, Really ?
-
0:30 - 0:55 Micro-challenges and review
-
0:55 - 1:00 Break
-
1:00 - 1:50 Labs - Learnyounode
-
1:50 - 2:00 Review
-
NodeJS Resources
-
Technological Backgrounds
- Google V8 Javascript Engine
- Javascript - essentially evented
- NodeJS != express - Modularity via Packages
-
General Capabilities
- Speed
- Database (mysql, mongo, etc..), other I/O bound tasks
- NOT large amounts of computation
-
Fundamental Concepts
- being bound (IO, CPU, etc..)
- Eventedness
- Concurrency - Threads vs. Processes vs. Event Loop
- Callstacks
- Function passing
- setTimeOut - throw a task into the future (and while waiting, wha???)
-
Learn you node
npm install -g learnyounode
-
Props (credits)
Micro-challenges :
console.log("Hello from Node")
// defer the execution of this
console.log("Goodbye from Node")
// and let this run right away
console.log("Hangin' with Node")
function say(word) {
console.log(word);
}
// write a function execute which enables the following
execute(say, "Hello");
var fs = require('fs');
// turn this pseudo-code into real code
//
// contents = fs.readFile('somefile.txt')
// console.log("Look at all my money: " + contents);
//
// Hint: lookup the docs for fs.readFile and compare fs.readFileSync
var http = require("http");
function onRequest(request, response) {
console.log("Request received.");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
http.createServer(onRequest).listen(8888);
console.log("Server has started.");
// test with browser or
// curl -v http://127.0.0.1:8888/
// ab -n 1000 -c 200 http://127.0.0.1:8888/