I want to use node.js in my next project, but my boss does not like that our competitors can read the source code.
Is there a way to protect the JavaScript code?
You can use EncloseJS - compiler for node.js projects. It really compiles JavaScript to native code, and your sources are not included to binary.
Package your core logic into modules.. these modules can be built then run through Google's closure. You could even be able to do this as a Grunt task as part of your build process.
It's an old question but worth pointing out. Note: nothing you do will truly hide your code, but neither will anything shipped via .Net (C#) or Java for that matter. In general, simply using a tool like uglify, or closure should be enough of an obfuscation point. By being modular and using closure you can actually do a lot of optimizations that otherwise would be difficult.
Check this article.
I will show you how to “truly” compile Node.js (JavaScript) code to V8 Bytecode. This allows you to hide or protect your source code in a better way than obfuscation or other not-very-efficient tricks (like encrypting your code using a secret key, which will be embedded in your app binaries, that’s why I said “truly” above).
So, using bytenode tool, you can distribute a binary version .jsc of your JavaScript files. You can also bundle all your .js files using Browserify, then compile that single file into .jsc.
Check bytenode repository on Github.
you can use packer for nodejs for obfuscate your script...
JXcore (node.js 0.11.X distro) has its own JX packaging feature that secure the source code and assets. You can even select whether that particular package can be used from other applications or not. (standalone OR library)
Let's say you have many JS etc. files and the entry point to your module is something like;
exports.doThis = function() { ...... };
if you simply call the method below and compile it to JX package, the source code will be safe.
jxcore.utils.hideMethod(exports.doThis);
this is (method hiding) would only required for the entry file since all the other sub JS files not reachable from the calling application.
You need JXcore to run JX packages.
More information is available from JXcore
Just include a license agreement and give them the source code. They might want to customize it anyway.