Blog Spot!


Node.js Best Practices

logo

Table of Contents as of 2018-10-12

  • Project structure Practices (5)
  • Error Handling Practices (11)
  • Code Style Practices (12)
  • Testing And Overall Quality Practices (9)
  • Going To Production Practices (18)
  • Security Practices (24)
  • Performance Practices (in progress)

github

Added on 12.Dec.2018
Tags: node best practices development

Apache2 as a Reverse Proxy

Basic Example:

<IfModule mod_ssl.c>

    <VirtualHost *:8080>

        # the ptoxy shit
        ProxyPreserveHost On
        ProxyPass        "/" "http://localhost:3000/"
        ProxyPassReverse "/" "http://localhost:3000/"
        ServerName www.sub.domain.com

        # SSL Support
        SSLCertificateFile /etc/letsencrypt/live/sub.domain.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/sub.domain.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
    </VirtualHost>

</IfModule>

Enable this mods:

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests

... and don't forget to make Apache listen to the desired port, in this example port: 8080

apache docs

Added on 12.Dec.2018
Tags: apache proxy httpd server configs

23+ Node.js security best practices

Added on 21.Nov.2018
Tags: node noejs js security http express

How to atomically delete keys matching a pattern using Redis

redis-cli KEYS *YOUR_KEY_PREFIX* | xargs redis-cli DEL

stackoverflow

Added on 15.Nov.2018
Tags: linux terminal redis db cli

Laravel queue solution for shared hosting

laracasts

What I have done in a similar situation (I have shared cpanel hosting and no way to install supervisor) I used the cron to run laravel's scheduler every minute and inside I used this:

$schedule->command('queue:work --daemon')->everyMinute()->withoutOverlapping();

So whats happening is, the first time it runs, it will start the queue worker in daemon mode, then on every minute it will basically use the withoutOverlapping to only run it again if the previous one crashed/exited/no longer running. This essentially produces a supervisor like functionality. At worst case it will take a minute before the queue worker comes back up in case of a failure / memory limit hit, but in most cases the first thread will stay alive and work through the queue. This is a better way to accomplish queue:listen like functionality without supervisor.

The caveat is of course, you need to run queue:restart whenever you deploy new code so that the daemon worker will restart and get fresh app code.

Hope this helps.

Added on 03.Sep.2018
Tags: laravel lumen queue shared hosting.

Search


PHP Libraries


Carbon lib / docs
Idiorm lib / docs
Image Workshop lib / docs
lorenzos/Minixed lib / docs
Parsedown lib / docs
PHP Paginator lib / docs
PHP Redis lib / docs
QrCode lib / docs
Requests lib / docs
Slim lib / docs
Spyc lib / docs
TWIG lib / docs
Upload lib / docs
Validation lib / docs
Zebra Image lib / docs

JS Libraries


AJV lib / docs
BackboneJS lib / docs
Bootstrap Notify lib / docs
C3.js lib / docs
ChartJS lib / docs
FastMD5 lib / docs
HighlightJS lib / docs
jQuery-Storage lib / docs
JS-Cookie lib / docs
Leaflet JS lib / docs
LowDB lib / docs
Marked lib / docs
NeedlyJS lib / docs
ParcelJS lib / docs
RequireJS lib / docs
Swig lib / docs
Toastr lib / docs
Underscore lib / docs
ValidateJS lib / docs
top