4. When to use it?
Gergely Nemeth
● Lots of non-blocking operations
● JSON APIs
● Reuse code across the client and the server
● Shelling out to unix tools
● Streaming data
● Crawling
5. When to forget it?
LongDatabaseOperation.on(‘finish’, function () {
//won’t be called!
});
while (true) {
//do some stuff
}
Gergely Nemeth
● Computationally heavy applications
6. When to forget it?
LongDatabaseOperation.on(‘finish’, function () {
//won’t be called!
});
while (true) {
//do some stuff
}
Gergely Nemeth
● Computationally heavy applications
1. All code runs in a single thread
2. Functions listen on events, act and sleep
7. How?
Gergely Nemeth
● Download from: http://nodejs.org/ (or nvm on unix-based systems)
● Hello world:
// Load the http module to create an http server.
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello Worldn");
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);
// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");
● Run with: node app.js