介绍适用于Visual Studio的node.js工具

node.js and Express running in VS

Just when you thought it couldn't be crazier in Redmond, today they are introducing node.js Tools for Visual Studio!

就在您以为在雷德蒙德(Redmond)不再疯狂时,今天他们才推出Visual Studio的node.js工具

NTVS runs inside VS2012 or VS2013. Some node.js enthusiasts had forked PTVS and begun some spikes of node tools for VS. At the same time the PTVS team was also working on node.js integration, so they all joined forces and made NTVS a community project. NTVS was developed by the same team that brought you PTVS with help from friends like Bart Read from Red Gate (he did the npm GUI), and Dmitry Tretyakov from Clickberry for several debugger fixes & features.

NTVS在VS2012或VS2013内部运行。 一些node.js发烧友分叉了PTVS,并开始为VS添加一些峰值的节点工具。 同时,PTVS团队还致力于node.js集成,因此他们全力以赴,使NTVS成为社区项目。 NTVS是由同一个团队开发的,该团队在诸如Red Gate的Bart Read (他做过npm GUI)和Clickberry的Dmitry Tretyakov之类的朋友的帮助下为您带来了PTVS ,它们提供了一些调试器修复和功能。

NTVS is open source from the start, and has taken contributions from the very start. It supports Editing, Intellisense, Profiling, npm, Debugging both locally and remotely (while running the server on Windows/MacOS/Linux), as well publishing to Azure Web Sites and Cloud Service.

NTVS从一开始就是开源的,并且从一开始就做出了贡献。 它支持编辑,Intellisense,分析,npm,本地和远程调试(在Windows / MacOS / Linux上运行服务器时),以及发布到Azure网站和Cloud Service。

It's actually pretty freaking amazing how they did it, so I encourage you to download it and give it a try because some of the stuff (even given this is an alpha) is very very clever.

实际上,它们是如何实现的,实在令人惊讶,因此,我鼓励您下载并尝试一下,因为其中一些内容(即使是Alpha版本)也非常聪明。

Blank Express Application

Node.js Tools for Visual Studio takes advantage of V8 Profiling API's as well Visual Studio's Reporting features to give you a sense of where your program is spending its time.

用于Visual Studio的Node.js工具利用了V8 Profiling API以及Visual Studio的Reporting功能,使您可以感觉到程序在哪里花费时间。

NOTE: See that File | New Project dialog up there? Visual Studio organizes things by language, so node.js is under JavaScript. But you've also got Python and Django, iOS and Android via C#, TypeScript, VB, F#, all in Visual Studio.

注意:看到该文件| 新建项目对话框在那里? Visual Studio按语言组织事物,因此node.js在JavaScript下。 但是您还可以通过Visual Studio中的C#,TypeScript,VB,F#获得Python和Django,iOS和Android。

One of the things that's impressed me about the way they integrated node.js into Visual Studio was that they didn't try to recreate or re-do things that already worked well. It's node, it runs node.exe, it uses the V8 debugger, it uses the V8 profiler because that's what people use. Duh. But, for example, NTVS can take the output from the V8 profiler and display it using the Visual Studio Profiler Reporting Tools. No need to reinvent the wheel, just use the right tool for the job.

他们将node.js集成到Visual Studio中的方式使我印象深刻的一件事是,他们没有尝试重新创建或重新执行已经很好的工作。 它是节点,它运行node.exe,它使用V8调试器,它使用V8探查器,因为这是人们所使用的。 咄。 但是,例如,NTVS可以从V8探查器获取输出并使用Visual Studio探查器报告工具将其显示。 无需重新发明轮子,只需使用正确的工具即可。

使用针对Visual Studio的node.js入侵Ghost博客引擎 (Hacking on the Ghost blogging engine with node.js for Visual Studio)

Let's look at an example.

让我们来看一个例子。

From within Visual Studio, go File New Project, click JavaScript, then "From Existing Node.js code."

在Visual Studio中,转到“文件新项目”,单击“ JavaScript”,然后单击“从现有Node.js代码”。

From Existing node.js Code

Point NTVS to your Ghost folder.

将NTVS指向您的Ghost文件夹。

Create from Existing Code

Then tell node.js for VS that the startup file is index.js, hit Next, save the project file and Finish.

然后告诉VS的node.js,启动文件是index.js,单击“下一步”,保存项目文件并单击“完成”。

Create New Project from Existing Code

At this point, you've got Ghost inside VS.

至此,您已经在VS中安装了Ghost。

Random: that since I have Web Essentials I also get a nice split-screen markdown editor as well.

随机:因为我有Web Essentials,所以我也得到了一个不错的分屏降价编辑器。

From here, just hit F5 to Debug, or Ctrl-F5 to start without Debugging. Also notice the properties of the Project in the lower right corner there showing the node path and port as well as the Startup File. You can change these, of course.

在这里,只需按F5键即可进行调试,或按Ctrl-F5键即可开始进行调试。 还要注意右下角的项目属性,其中显示了节点路径和端口以及启动文件。 您当然可以更改这些。

Ghost inside Visual Studio with NTVS

Here's me running Ghost locally. You can see the path to node, the ghost.js file and my browser.

这是我在本地运行Ghost。 您可以看到节点的路径,ghost.js文件和我的浏览器。

Running Ghost in VS with node for VS

You'll get good intellisense for completions and help for method signatures.

您将获得很好的智能感知,可以完成操作并获得方法签名的帮助。

Intellisense example

调试 (Debugging)

Node.js Tools for Visual Studio includes complete support for debugging node apps. This includes support for Stepping, Breakpoints, "Break on exception", as well as Locals, Watch, Immediate and Call Stack tool windows.

适用于Visual Studio的Node.js工具包含对调试节点应用程序的全面支持。 这包括对步进,断点,“异常中断”以及本地,监视,立即和调用堆栈工具窗口的支持。

You can manage Exceptions just like any other language service. See in the dialog below node.js exceptions are listed along with other exceptions in managed and unmanaged code.

您可以像处理其他任何语言服务一样管理异常。 请在下面的对话框中查看,列出了node.js异常以及托管和非托管代码中的其他异常。

Managing Exceptions in node.js for Visual Studio

The debugging still happens like it always has, with the node V8 debugger, except Visual Studio connects to the debugger over another socket (remember, you can even debug node.js remotely running on a Linux or Mac like this!) and translates how V8 thinks into how Visual Studio thinks about debugging. The experience is seamless.

使用节点V8调试器,调试仍然像往常一样进行,只是Visual Studio通过另一个套接字连接到调试器(请记住,您甚至可以像这样调试在Linux或Mac上远程运行的node.js!)并转换V8的方式。考虑Visual Studio如何考虑调试。 体验是无缝的。

See in this screenshot, you can see node.exe is being debugged, I'm running Ghost. You can see my Call Stack, and the Locals in the Watch Window. I can inspect variables, step around and do everything you'd want to do when debugging a Web App.

在此屏幕快照中看到,您可以看到正在调试node.exe,我正在运行Ghost。 您可以在“监视”窗口中看到我的呼叫堆栈和本地用户。 在调试Web App时,我可以检查变量,遍历并做您想做的所有事情。

Debugging Session of Ghost in VS with Node Tools for Visual Studio

npmVisual Studio (npmVisual Studio)

The npm experience is pretty cool as well. Node.js for Visual Studio is always watching the file system so are more than welcome to run npm from the command line or from within the node immediate window and Visual Studio will see the changes.

NPM体验也很酷。 适用于Visual Studio的Node.js始终在监视文件系统,因此非常欢迎从命令行或在节点即时窗口内运行npm,Visual Studio将看到所做的更改。

You can also use the npm Package Management dialog and search the repository and install packages graphically. It's up to you.

您还可以使用“ npm软件包管理”对话框并搜索存储库并以图形方式安装软件包。 由你决定。

npm package management within VS

Here's a package installing...

这是一个安装包...

Installing a module

The physical node_modules and how modules are handled is pure node...VS doesn't touch it or care. However, the Solution Explorer in Visual Studio also presents a logical view on top of the physical view.

物理node_modules以及模块的处理方式是纯节点... VS不在乎它。 但是,Visual Studio中的解决方案资源管理器还在物理视图之上提供了逻辑视图。

image

NOTE: I really like this. I think it has potential and I'd even like to see references in .NET treated like this. The physical and the logical, along with a dependency tree showing NuGet packages. It helped me understand the project much better.

注意:真的很喜欢。 我认为它具有潜力,我甚至希望看到.NET中的引用被这样处理。 物理和逻辑,以及显示NuGet程序包的依赖关系树。 它帮助我更好地了解了该项目。

There's lots more. There's an REPL interactive window, and you can just publish like any other web project using the same Publish Wizard that ASP.NET projects use. You can publish node.js apps directly to Azure as well, either with Git or with Visual Studio publishing.

还有更多。 有一个REPL交互式窗口,您可以像使用ASP.NET项目使用的同一“发布向导”一样,像其他任何Web项目一样进行发布。 您也可以使用Git或Visual Studio发布将Node.js应用程序直接发布到Azure。

You can also remotely debug node instances running on other machines by starting node with the included Remote Debugging Proxy.

您还可以通过使用随附的远程调试代理启动节点来远程调试在其他计算机上运行的节点实例

image
node.exe RemoteDebug.js -machineport 5860 script.js

As mentioned, you can do remote debugging between Visual Studio and node running on any server OS.

如前所述,您可以在Visual Studio和任何服务器操作系统上运行的节点之间进行远程调试。

结论 (Conclusion)

I'm personally pretty happy with the way that Visual Studio is turning (in a short amount of time, seems to me) into quite the competent language and environment factory.

我个人对Visual Studio正在(在我看来很短的时间内)转变成相当称职的语言和环境工厂的方式感到非常满意。

Node.js Tools for Visual Studio is entirely open source under the Apache license and they welcome contributions and bug reports. It's Alpha and it's early but it's awesome. Go get it. Big congrats to all involved!

适用于Visual Studio的Node.js工具在Apache许可下是完全开源的,并且欢迎您提供文稿和错误报告。 它是Alpha,时间还早,但是很棒。 去得到它。 恭喜所有参与人员!

Disclosure: FYI, Red Gate does advertise on this blog, but it was a total coincidence that a Red Gate employee helped with node.js Tools for VS. I just found that out today. They are very nice people.

披露:仅供参考,Red Gate确实在此博客上做广告,但这完全是巧合,Red Gate员工提供了node.js Tools for VS帮助。 我今天才发现的。 他们是非常友善的人。

翻译自: https://www.hanselman.com/blog/introducing-nodejs-tools-for-visual-studio

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值