O'Reilly logo

The Node Craftsman Book by Manuel Kiessling

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required