As a server-side technology, Node.js has one obvious limitations that experienced full-stack or back-end web developers will notice. Unlike Java or ASP.NET, the language is interpreted rather than compiled.
Compiled code already consists of processor instructions that anyone, even the most experienced software developers, would struggle to read. This is, however, the format that the CPU understands with the minimal amount of pre-processing.
Interpreted code, on the other hand, is the code that is deployed in exactly the same state as it has been originally written in. Every statement is read and translated into a set of processor instructions in real time, which makes the execution somewhat slower.
Another disadvantage of interpreted languages is that the production code is stored in easily accessible text files, while compiled code is stored in inaccessible binary format. Interpreted language is then, obviously, not the best choice for any closed-source app. Therefore, if you are working with a back-end technology that compiles into something that is fast and obfuscated, you may ask, why should I bother learning Node.js?
Flexibility achieved via Node Package Manager
What makes Node.js super-flexible and suitable for many types of applications is a tool that comes with it: NPM, which stand for Node Package Manager. For those ASP.NET developers who are familiar with NuGet packages or Java developers who are familiar with Maven repository will grasp NPM in no time.
This tool allows developers to publish libraries, frameworks and various other tools and add-ons that work with Node.js into an online repository. You can use NPM in your command line to download any of the countless packages that are publicly available.
One of the key files in a Node.js application is package.json. This is a configurational file where you specify all dependencies from NPM repository that you will need in order to be able to run your application.
When you launch your Node.js application, magic happens. The runtime will automatically download any dependency that is specified in the file. As well as this, an IDE’s compatible with Node.js will highlight errors in your code when you forgot to add a critical dependency to your source.
The way packages are managed via NPM is very useful in server-side deployment scenario. You cannot always know ahead of time what Node.js dependencies are already available on the server. So you only deploy the code of your application itself and any third party dependencies will resolve themselves if needed.
Defining objects with strict data structure and keeping each of them separate from the actual code was a no-go. This resulted in developers spending some time navigating through the code to see how the logic flows.
To improve the process even further, the concept of transpilation has been fully taken advantage of by various Node.js tools. The term is a combination of two words: translation and compilation.
The process works in a similar way to traditional compilation process, but, as the code is not actually converted into a language that is meant to run close to the hardware, translation, rather than compilation, is what actually happens.
Once your client-side code is in production, there is no longer need to make it easily readable. Therefore, NPM contains various tools to bundle and minify your code.
The commonly accepted standard used by various client-side Node.js frameworks is to combine the code that has been downloaded from various NPM dependencies into a JS file called vendor bundle and to combine the actual custom application code into either app bundle or main bundle, depending on the framework.
So, the code files that you actually write are not the files that will be deployed. The output files will be deposited into a separate folder by a dedicated tool installed by NPM, not dissimilar to how C# code is compiled into DLL files, which are deposited into “bin” folder.
Minification is the process of changing your code in such a way that it remains the same functionally, but becomes much more compact visually. This is achieved by removing non-functional characters, such as white spaces and changing descriptive variable names into single-letter identifiers. This makes your code much smaller than the combined size of all of the files that were combined to produce it.
Also, it provides some degree of protection against unwanted attention. The process does not obfuscate the code to the same degree as compilation does, as the output code is still contained within text files. However, it makes the code difficult enough to read that most of people will not even bother. UglifyJS is one popular NPM library that is used to perform minification.
How Aurelia and Angular take advantage of Node.js infrastructure
Node.js environment for Angular is also what Microsoft has officially embraced. In MSDN Magazine, one of the official magazines for developers who use Microsoft technologies, Ted Newman has a column with a title “The Working Programmer – How To Be MEAN“, where he talks about the best ways to develop a web application using the latest version of Angular, which has embraced a modular design inspired by Node.js. In fact, MEAN stands for Mongo, Angular and Node.js.
Aurelia is a framework not too dissimilar from Angular. In fact, it was created by one of the people who used to work on version 2 of Angular, where modular design was first introduced. Arguably, Aurelia is the easiest one of the two to master, while having all the same functionality.
If you will pick one of the frameworks and will go through its official tutorial written specifically for Node.js environment, you will see for yourself how easy it is to get started. So, give it a go. I am pretty sure that you will be pleasantly.