Manage How Your Application Uses Memory

Since the process thread is shared among all the clients, memory is also shared. You should avoid storing much information in memory per request because it can accumulate over concurrent clients and your process can die simply because it runs out of memory. In threaded servers, a thread usually has a separate memory limit that’s reached long before the whole server process runs out of memory, so only the thread gets terminated instead of the whole process. However, Node.js, being in a single thread, will kill the whole process. Let’s look at a common mistake where memory is overtaxed:

​ ​'use strict'​;
​ 
​ ​var​ express = require(​'express'​);
​ ...

Get Secure Your Node.js Web Application now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.