result = db.executeQuery("SELECT name FROM Customers WHERE id=1");
// Wait for result
// Do something with result
The Traditional Model
db.executeQuery("SELECT name FROM Customers WHERE id=1", function(result, error){
// Do something with the result
});
The Node Model
What is Node.js Good At?
The Node.js Ecosystem
What is Node.js Not Good At?
var http = require('http');
var server = http.createServer(function(request, response) {
console.log('Request received');
// Long CPU operation
for(var i=0; i<100000000; i+=1){
console.log(i);
}
// After which response is sent
response.write(200, {"Content-Type": "text/html"});
response.write("hello");
response.end();
});
server.listen(1256);
Demo
Who is using Node.js?
The thing it’s best at doing is talking to other services. The mobile app has to talk to our platform API and database. – LinkedIn’s mobile development lead Kiran Prasad
And many more
/