

Node apps crash when they encounter an uncaught exception. For a detailed comparison of these two libraries, see the StrongLoop blog post Comparing Winston and Bunyan Node.js Logging. If you’re logging app activity (for example, tracking traffic or API calls), instead of using console.log(), use a logging library like Winston or Bunyan. But then, you’re not really going to debug in production, are you? For app activity To keep your app purely asynchronous, you’d still want to pipe console.error() to another program. This module enables you to use the DEBUG environment variable to control what debug messages are sent to console.error(), if any. If you’re logging for purposes of debugging, then instead of using console.log(), use a special debugging module like debug. But these functions are synchronous when the destination is a terminal or a file, so they are not suitable for production, unless you pipe the output to another program. Using console.log() or console.error() to print log messages to the terminal is common practice in development. In general, there are two reasons for logging from your app: For debugging and for logging app activity (essentially, everything else). See the node command-line options documentation for more information.
#Hightail express linux code#
Of course, you wouldn’t want to use this in production, but rather to ensure that your code is ready for production. If you are using Node.js 4.0+ or io.js 2.1.0+, you can use the -trace-sync-io command-line flag to print a warning and a stack trace whenever your application uses a synchronous API. The only time when a synchronous function can be justified is upon initial startup. Avoid their use in production.Īlthough Node and many modules provide synchronous and asynchronous versions of their functions, always use the asynchronous version in production. A single call to a synchronous function might return in a few microseconds or milliseconds, however in high-traffic websites, these calls add up and reduce the performance of the app. Synchronous functions and methods tie up the executing process until they return. For details on enabling gzip compression in Nginx, see Module ngx_http_gzip_module in the Nginx documentation. In that case, you do not need to use compression middleware. For example: const compression = require('compression')įor a high-traffic website in production, the best way to put compression in place is to implement it at a reverse proxy level (see Use a reverse proxy). Use the compression middleware for gzip compression in your Express app. Gzip compressing can greatly decrease the size of the response body and hence increase the speed of a web app.

Here are some things you can do in your code to improve your application’s performance:

This article discusses performance and reliability best practices for Express applications deployed to production.

Production best practices: performance and reliability Overview
