node.jspci-compliance

How to remove variable from the server memory?


I have an nodejs application that required to compliance to PCI/DSS standard.

Example :

let number = "91029039102930193092"

How can I remove it effectively from memory or V8 Garbage Collector (GC)?

Can I do this: number = "" to reset it to empty string?


Solution

  • You can run node with --expose_gc flag. In your code then you can do

    number = ""; 
    

    or

    delete number;
    

    and after this force gc

    global.gc();
    

    This will give you possibility to immediately free memory

    delete number;
    global.gc();
    

    and safer way

    number = undefined;
    global.gc();