Dr. Andrew Besmer
The Basics
//start_finish.js
var http = require('http');
http.createServer(function(request, response) {
response.writeHead(200);
response.write("Started.\n");
setTimeout(function () {
response.write("Finished.\n");
response.end();
}, 5000);
}).listen(8000);
console.log('listening on port 8000...');
//start_finish.php
<?php
echo "Started";
sleep(5);
echo "Finished";
ab -r -n 1000 -c 1000 http://node
ab -r -n 1000 -c 1000 http://php
start_finish.js timeline comparrison blocking vs non-blockingvar startTime = new Date().getTime();
while (new Date().getTime() < startTime + 5000);//hello.js
var name = "World"
console.log("Hello " + name);
__filename - Absolute path to file executing the code__dirname - Absolute path to directory the code is inmodule - Reference to the current moduleexports - Reference to module.exports used to provideprocess - Work with the current running node process
process.argv - Get the argument vectorsetTimeout(), setInterval(), clearInterval(), console()process.argvNote that some of these are per module thus not actually global↩