With the Edge.js project, you can run both Node.js and. NET code in one process. In this article, I will discuss the motives behind this project and describe the basic mechanisms that edge.js provides. A few edge.js scenarios will then be explored to help you develop node.js programs in these scenarios.
Why do you use Edge.js?
While many applications can only be written with node.js, in some cases they need to combine the benefits of both node.js and. Net. For several reasons, you want to use it in a program. NET and node.js:.net frameworks and NuGet packages provide a rich functional ecosystem that complements node.js and NPM modules; you might want to reuse some ready-made. NET components in a node.js program Or you might want to use multithreaded CLR to run CPU-intensive computing, which is by no means a single-threaded node.js, or you might prefer to use the. NET Framework and C # rather than using C + + Write native Node.js extensions to access operating system mechanisms that have not yet been exposed through node.js.
Once you decide to use node.js and. NET in your program, you must separate the node.js and. NET components with process barriers and establish some form of interprocess communication mechanism, such as http:
Edge.js provides another way to build a heterogeneous system like this. It allows you to run both Node.js and. NET code in a single process, and provides an interoperability mechanism between V8 and the CLR.
With Edge.js, you can run Node.js and. NET in one process without splitting it into two processes, which has two main benefits: better performance and lower complexity.
Performance tests for a scenario show that the edge.js request from Node.js to C # is 32 times times faster than the same request sent over HTTP between two processes. Compared to two processes and interprocess communication channels, handling only a single process significantly reduces the complexity of the deployment and maintenance you need to address.
. NET Welcome Node.js
Next I'll explain the key concepts of edge.js with a basic example of sending a request from Node.js to C #.
Line 1th introduces the Edge module installed in advance from NPM. Edge.js is a native node.js component. The special thing about Edge.js is that when it is loaded, it starts hosting the CLR within the Node.exe process.