Skip to content
Snippets Groups Projects
Commit e503a6f1 authored by Stefan Dierauf's avatar Stefan Dierauf
Browse files

added more slides

parent f6e7a44a
No related branches found
No related tags found
No related merge requests found
var http = require('http');
function requestHandler(request, response) {
response.writeHead(200, {'Content-Type': 'text/html'});
response.end('<h1>MLP Fan Site</h1>');
}
http.createServer(requestHandler).listen(1337, '127.0.0.1');
## Event Loop ## Event Loop
* Async calls enqueued on event loop * Async calls enqueued on event loop with a callback
* Node single-thread will dequeue and process * Node single-thread will dequeue and run callback
* When there's nothing left to do, node will sleep * When there's nothing left to do, node will sleep
* Everything should be asynch as possible!
\ No newline at end of file
...@@ -16,5 +16,9 @@ ...@@ -16,5 +16,9 @@
"outline-pt2.md", "outline-pt2.md",
"the-javascript-part.md", "the-javascript-part.md",
"what-is-a-callback.md", "what-is-a-callback.md",
"event-loop.md" "event-loop.md",
"simple-server-example.md",
"popular-modules.md",
"other-crazy-things-you-can-do.md",
"takeaways.md"
] ]
\ No newline at end of file
## Other crazy things you can do
* Program arduino (node-serialport)
* Write standalone apps with html + js (node-webkit)
* Probably shouldn't do this
* Write node plugins in c++ (node-gyp)
* Feel smug + hipster
\ No newline at end of file
## Popular modules
* http://expressjs.com/ -- minimalist web framework
* http://gruntjs.com/ -- task runner
* http://yeoman.io/ -- project scaffolding/generator
* http://browserify.org/ -- frontend module system/bundling
<br>
...and many more!
\ No newline at end of file
## Simple server example again
```javascript
var http = require('http');
function requestHandler(request, response) {
response.writeHead(200, {'Content-Type': 'text/html'});
response.end('<h1>MLP Fan Site</h1>');
}
http.createServer(requestHandler).listen(1337, '127.0.0.1');
```
* Each request to the server is enqueued
* Uses `requestHandler` as the callback
\ No newline at end of file
## Takeaways
Nodejs...
* is fast
* is simple
* uses a popular language
* lets the OS worry about concurrency
* has plenty of support + good docs
* isn't php
## The javascript part ## The javascript part
* Javascript is one of the most popular languages in the world * Javascript is one of the most popular languages in the world
<img src="pics/github_new.png" style="width: 400px">
* Lots of people with knowledge of javascript * Lots of people with knowledge of javascript
* Ergo, lots of people familiar with async + callbacks * Ergo, lots of people familiar with async + callbacks
* Nodejs uses lots of async + callbacks * Nodejs designer wanted a language with callbacks + event loop concept
\ No newline at end of file * Google V8 ayy lmao
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Servers have to handle lots of requests * Servers have to handle lots of requests
* majority of I/O is disk bound * majority of I/O is disk bound
``` ```javascript
var result = database.query("kittens"); var result = database.query("kittens");
// twaddle fingers // twaddle fingers
send(result); send(result);
......
...@@ -10,3 +10,4 @@ database.query("kittens", function (data) { ...@@ -10,3 +10,4 @@ database.query("kittens", function (data) {
// do other servery things // do other servery things
``` ```
*we'll explore callbacks and javascript language features later*
...@@ -3,9 +3,6 @@ ...@@ -3,9 +3,6 @@
Callbacks are functions that are passed as parameters to other functions, Callbacks are functions that are passed as parameters to other functions,
and then called within those functions and then called within those functions
LinkedList implementation requires a function pointer to free a payload,
same idea
``` ```
function helloCaller(helloFn, name) { function helloCaller(helloFn, name) {
helloFn(name); helloFn(name);
......
## Why node is awesome ## Why node is awesome
Simple http server
```javascript ```javascript
var http = require('http'); var http = require('http');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment