Search code examples
javascriptserver-side

Can I use JavaScript instead of PHP, replacing Apache with Node.js?


Can I write my web-site only in JavaScript being sure that my code is concealed from anyone? In this respect, is Node.js, like Apache, can be given access to through an Internet-provider?


Solution

  • The answer to both of your questions is yes.

    Node.js can completely replace Apache (assuming you are willing to re-write all of your PHP as JavaScript). If you have your Apache running in reverse-proxy mode between your server and client, you can even handle some requests in Node.JS while handing others in PHP. This will allow you to maintain original functionality while changing the code out, and also allow PHP to handle more mundane tasks.

    While you cannot prevent raw JavaScript from being read through any means of obfuscation, you can prevent people from reading your code by note making use of standard JavaScript at all. You can use a NativeExtension for Node to add an extension handler for encrypted JavaScript files:

    require.extensions[".jse"] = function (m) {
     m.exports = MyNativeExtension.decrypt(fs.readFileSync(m.filename));
    };
    
    require("YourCode.jse");
    

    This will convert your JavaScript code to a .jse, which you would then package for production. Considering the encryption is done inside the native extension, the encryption key wouldn't be revealed.

    Hope this helps! :)