node.js edge_“这只是软件问题”-Edge.js在三个平台上将Node和.NET整合在一起

Edge.js是一款允许在Windows、Mac和Linux上跨进程运行Node.js和.NET代码的库。它创建了两者之间的交互通道,解决了不同平台间通信的软件问题。借助Edge.js,开发者可以轻松地在Node.js应用中调用.NET代码,实现如CPU密集型任务的处理,或者使用C#编写Node.js的原生扩展,甚至支持在Node.js中执行Python、PowerShell等脚本。
摘要由CSDN通过智能技术生成
node.js edge

node.js edge

.NET and node together on three platforms

There was an engineer I used to work with who always said "That's just a software issue." No matter how complex the issue, no matter how daunting, they were confident it could be solved with software.

我曾经和一位工程师一起工作,他总是说“那只是软件问题”。 无论问题多么复杂,无论多么艰巨,他们都相信可以用软件解决。

.NET and C# and NuGet and the community have been making some amazing stuff in the last few years like ScriptCS, Chocolately, Boxstarter. Azure Websites now supports ASP.NET, sure, but also PHP, Python, Java (Tomcat or Jetty or your own container), and node.js. Getting these things to work together has been an interesting software issue. Apps can run side-by-side, but they can't really talk to each other in-process. (Mostly one just moves data between universes over JSON and HTTP when need-be.)

.NET和C#和的NuGet和社会各界一直在在过去的几年里像一些惊人的东西ScriptCSChocolatelyBoxstarter 。 当然,Azure网站现在支持ASP.NET,还支持PHP,Python,Java(Tomcat或Jetty或您自己的容器)和node.js。 使这些东西协同工作一直是一个有趣的软件问题。 应用程序可以并行运行,但是它们实际上并不能在进程中相互通信。 (在需要时,大多数人只是通过JSON和HTTP在Universe之间移动数据。)

However, Tomasz Janczuk has been working on Edge.js (on Github) for a while now. I showed his work at jQuery Portland last year, but this week he's taking it to the next level. He is creating a wormhole between software universes.

但是, Tomasz Janczuk已经在Edge.js (在Github上)上工作了一段时间。 去年,我在jQuery Portland上展示了他的作品,但本周他将作品提升到了一个新的水平。 他在软件世界之间制造了一个虫洞。

Edge.js现在允许您在Windows,Mac和Linux上在进程中运行node.js和.NET代码。 (Edge.js now lets you run node.js and .NET code in-process on Windows, Mac, and Linux.)

The name is great. An edge connects two nodes, and Edge.js is that edge.

这个名字很棒。 一条边连接两个节点,Edge.js是该边。

node and .NET connected by edge.js

Here's a node app hello world node app calling .NET. Don't sweat that the .NET code is tunneled inside a comment, this is the Hello World proof of concept.

这是一个调用.NET的节点应用程序hello world节点应用程序。 不要担心.NET代码是在注释内传递的,这就是Hello World概念的证明。

var edge = require('edge');

var helloWorld = edge.func(function () {/*
async (input) => {
return ".NET Welcomes " + input.ToString();
}
*/});

helloWorld('JavaScript', function (error, result) {
if (error) throw error;
console.log(result);
});

Perhaps you have a bunch of CPU intensive work or algorithms in C#, but you've also got a node.js app that needs the result of that work. Edge can help with that.

也许您在C#中有大量CPU密集型工作或算法,但是您还拥有需要该工作结果的node.js应用程序。 Edge可以帮上忙。

You can bring in a CS or CSX file into node like this:

您可以将CS或CSX文件导入节点,如下所示:

var myCSharpCode = edge.func(require('path').join(__dirname, 'myCSharpCode.csx'));

You can bring code from a .NET DLL into a node.js compiled as well.

您也可以将.NET DLL中的代码带入已编译的node.js中。

var clrMethod = edge.func({
assemblyFile: 'My.Edge.Samples.dll',
typeName: 'Samples.FooBar.MyType',
methodName: 'MyMethod'
});

It's not a hack, it's a clear way to marshal between CLR threads and the V8 (the node Javascript engine) thread. It's also interesting from a comp-sci perspective as the CLR can have many threads and V8 has the one.

这不是黑客,而是在CLR线程和V8(节点Javascript引擎)线程之间进行调度的一种清晰方法。 从comp-sci的角度来看,这也很有趣,因为CLR可以有很多线程,而V8则有一个。

nodecsharp

Here's Tomasz's own words:

这是托马斯自己的话:

Edge.js provides an asynchronous, in-process mechanism for interoperability between Node.js and .NET.

Edge.js为Node.js和.NET之间的互操作性提供了一种异步的进程内机制。

You can use this mechanism to:

您可以使用此机制执行以下操作:

  • access MS SQL from Node.js using ADO.NET more...

    使用ADO.NET从Node.js访问MS SQL更多...

  • use CLR multi-threading from Node.js for CPU intensive work more...

    使用Node.js中的CLR多线程进行CPU密集型工作更多...

  • write native extensions to Node.js in C# instead of C/C++

    用C#而不是C / C ++将原生扩展写入Node.js
  • intergate existing .NET components into Node.js applications

    将现有.NET组件与Node.js应用程序互连

Read more about the background and motivations of the project here.

此处阅读有关该项目的背景和动机的更多信息。

Now, you might ask yourself, what problem does Edge.js solve? The answer is in the Edge.js FAQ.

现在,您可能会问自己,Edge.js解决了什么问题? 答案在Edge.js FAQ中

Go explore what you can do. Edge goes much further than just C# and Node. It works on Windows, OSX, and Ubuntu but you should just "npm install edge" as there's a node package available.

去探索你能做什么。 Edge不仅限于C#和Node。 它可以在WindowsOSXUbuntu上运行,但是您可以使用“ npm install edge ”,因为有可用的节点包

Have fun! You have a lot more power and flexibility than you think. It's just a software problem.

玩得开心! 您拥有的功能和灵活性比您想像的要强大得多。 这只是软件问题。

翻译自: https://www.hanselman.com/blog/its-just-a-software-issue-edgejs-brings-node-and-net-together-on-three-platforms

node.js edge

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值