Even though NodeJS is asynchronous in nature, you have to understand that all the code you write is not always non-blocking. Any function that is CPU-intensive or that waits for a return value before proceeding will block the current event loop. While the event loop is blocked, it cannot accept any new connections or process any ongoing requests.

A common piece of code that is blocking is the JSON.parse method. While most parsed strings are parsed relatively quickly, a large JSON string (several MB in size) could take up to a couple seconds to parse. At a small scale, this isn't such a big deal, but at a scale of several requests per second, the system can begin getting bogged down.

You can tell when your code is blocking when it expects a return value before proceeding. Take the code below for instance:

function fibonacci(n) {  
  if (n < 2) {
    return 1;

  else {
    return fibonacci(n - 2) + fibonacci(n-1);

console.log('Starting script...');  

See it in JSFiddle.net

If you run the script above, you'll notice it takes a couple seconds for the word Done. to be logged to the console. This is because it's waiting for the return value before continuing on.

Sometimes using code that blocks the event loop is unavoidable. The best way to handle this kind of code is to spin up a child process or use a worker script.

I'm also a big fan of lodash, but it might be a good idea to use the async library instead for complex loops or array/collection mapping.