NodeJS: the good parts?
Blogs20132013-10-24
NodeJS: the good parts? A Skeptic’s View
Here is a interesting video in youtube: NodeJS: the good parts? A Skeptic’s View, which I extract and did a simple summary. The node-promise is very interesting which I probably use in future.
------@@ Node.js ------ Long running computations => blocks event loop for other requests Need to run outside of main event loop Options: community: web workers threads Built-in: NodeJS child processes
Micro-service rchitecture
-
Modules
foo.js: exports.sayHello = function() {} var foo = require(“foo”); foo.sayHello();
-
Node as static files service:
fs.exists(filePath, function(exists) { if(exists) { res.writeHead(200, {“content-type”: mime.lookup(path.basename(filePath)) }); fs.createReadStream(filePath).pipe(res); } }); or: app.configure(function() { app.use(express.static(__dirname + ‘/public’)); });
-
RESTful WS with express/restify:(Easy URL routing and destructuring)
app.get(‘/portfolio/:userId’, function(req, res) { var portfolio = retrievePortfolio(req.params.userId); res.json(portfolio); });
— Use ‘request’ module to pass: Proxying to backend Servers
