• Blogs (9)
    • 📱 236 - 992 - 3846

      📧 jxjwilliam@gmail.com

    • Version: ‍🚀 1.1.0
  • 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

    1. Modules

      foo.js: exports.sayHello = function() {} var foo = require(“foo”); foo.sayHello();

    2. 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’)); });

    3. 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

    1. Deliverying events to the browser

      websocket, socket.io

    2. Promises (simply codes)

      https://github.com/kriszyp/node-promise