Optimizing code structure with async

The async module offers several other mechanisms for managing the control flow of our code. These are interesting even if our concern isn't performance optimization. Let's investigate them.

For these cases, let's remove the artificial slowness from the API server by removing the setTimeout operation, making the server respond immediately:

 'use strict'; var http = require('http'); var url = require('url'); var querystring = require('querystring'); http.createServer(function(request, response) { var pathname = url.parse(request.url).pathname; var query = url.parse(request.url).query; var id = querystring.parse(query)['id']; var result = { 'pathname': pathname, 'id': id, 'value': Math.floor(Math.random() ...

Get The Node Craftsman Book now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.