Skip to content

Instantly share code, notes, and snippets.

@bkanhu
Last active October 24, 2024 06:57
Show Gist options
  • Save bkanhu/dda7357d704d1eec0efa64bbeacc806f to your computer and use it in GitHub Desktop.
Save bkanhu/dda7357d704d1eec0efa64bbeacc806f to your computer and use it in GitHub Desktop.
NodeJS Backend production issues and fixes.

Production Bugs and Fixes

1. Avoid Using Nodemon in Production

Do not use Nodemon in the production environment as it is intended for development purposes only.

2. Configure PM2 with Ignore Paths

When running the backend using the Process Manager (PM2), ensure that all folder names are included as values of the ignore_path property in the ecosystem.config.js file.

module.exports = {
    apps: [
      {
        name: "jash-backend",
        exec_mode: "cluster",
        instances: "max",
        script: "./index.js",
        autorestart: true,
        args: "start",
        exp_backoff_restart_delay: 100,
        watch: true, // Still watch files, but exclude specific directories
        ignore_watch: ["node_modules", "uploads"], // Add the directories to ignore here
        max_memory_restart: "400M",
      },
    ],
};

3. Addressing Request Entity Too Large Errors

To resolve the "413 Request Entity Too Large" issue, take the following actions:

For NGINX Reverse Proxy:

  • Add the client_max_body_size directive to the NGINX configuration file:

 nginx    http {      client_max_body_size 50M;  # Adjust to the desired limit    }  

  • Test the NGINX configuration with the following command:
  sudo nginx -t
  • Restart NGINX to apply the changes:
  sudo systemctl restart nginx

For Apache Server:

  • Update the LimitRequestBody directive in your Apache configuration file, typically located at /etc/apache2/apache2.conf or within a virtual host configuration:

    apache     <Directory "/var/www/html">         LimitRequestBody 52428800  # 50MB in bytes     </Directory>    

  • Restart Apache to implement the changes:

    bash     sudo systemctl restart apache2    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment