📜 ⬆️ ⬇️

Extension Node.js Tools for Visual Studio

No matter how strange it may sound, Microsoft has officially introduced the Node.js Tools extension for Visual Studio !

Node.js Tools for Visual Studio The NTVS extension is intended for installation in Visual Studio versions 2012 and 2013. The project has a rather interesting story of its appearance. Several node.js fans almost simultaneously started developing their own extensions based on the PTVS project in order to create the Node.js Tools extension for Visual Studio. At the same time, the PTVS development team also performed work on integration with node.js, simultaneously uniting efforts of third-party developers, which ultimately led to the formation of the project community. The main efforts in creating NTVS were made by the PTVS team with the assistance of Bart Reed from Red Gate, who developed the GUI for npm, and Dmitry Tretyakov from Clickberry, who carried out work to improve the debugger and fix defects.

NTVS is an open source project, community-based input from the outset. Currently, the extension provides tools for easy code editing, intellisense, profiling, npm, local and remote application laying (on machines running Windows / MacOS / Linux), as well as publishing to Azure Web Sites and Cloud Services.

But it is much more interesting to look at all this in action, so do not miss the moment - download and experiment! Just note that some functions may work in an unusual way, since the project is still in the alpha version state.
')
Empty Express application

NTVS uses V8 profiling tools and Visual Studio Profiling Tools to easily analyze the performance of node.js applications.

Note : Having trouble choosing a template in the New Project dialog? Visual Studio groups them according to the language, so the node.js templates are located in the JavaScript category. Also here you can find Python and Django templates, iOS and Android on C #, TypeScript, VB, F # and many others.

One of the distinguishing features of NTVS is that the usual approach to developing projects in Visual Studio does not change. You just work with the node.js project, which is launched with the help of node.exe, using the usual debugger and V8 profiler. But with all this, it is extremely convenient that NTVS presents the V8 profiler data in the familiar Visual Studio Profiling Tools interface. No need to reinvent the wheel - using a ready-made tool.

Explore the Ghost Blog with Node.js Tools for Visual Studio


Consider the work of the extension in the following example.


In the Visual Studio window, go to File | New Project, select the category of JavaScript and click "From Existing Node.js code".

From existing source code

Specify the path to the Ghost folder in the NTVS window.

Create from existing source code

Then we specify in NTVS that the starting file is the index.js file, click Next and save the project by clicking Finish.

Creating a project from existing code

Everything is ready - we got the Ghost project in Visual Studio.

Note : since the Web Essentials extension is installed in Visual Studio, we can see the convenient markdown markup editor in the screenshot.

Now you can press F5 to debug or Ctrl-F5 to start without debugging. Please note that the path and port of the debugging node.js, as well as the startup file can be changed in the project properties.

Ghost in Visual Studio with NTVS

In the next image you can see Ghost running locally. In addition, you see the path to the running node.js process, the ghost.js file, and the browser window.

Running Ghost in VS with NTVS

After installing NTVS, Intellisense becomes available with detailed information on most node.js modules.

Intellisense example

Debugging


NTVS includes full debugging of the node.js application. The list of functions includes step-by-step debugging, breakpoints, stopping when exceptions occur, as well as the Locals, Watch, Immediate and Call Stack windows.

You can manage exceptions as in any other Visual Studio language. The following image shows the list of node.js exceptions along with other types of exceptions in managed and unmanaged code.

NTVS Exception Management

Debugging of applications is performed in the traditional way for node.js, except that Visual Studio connects to the V8 debugger via a separate socket (do not forget that you can remotely debug node.js applications running on Linux or Mac). All other debugging tricks are done using the usual Visual Studio controls.

The following image captures the debugging process of the Ghost. Notice the Call Stack, Locals and Watch windows. During debugging, you can view the values ​​of variables and perform the steps as in a normal web application.

Debugging Ghost in VS with Node Tools for Visual Studio

NPM for Visual Studio


For the convenience of working with npm, NTVS has used a variety of tools, including including monitoring the file system of the project. Thus, you can run npm both from the command line and from the Immediate window, and Visual Studio will track changes.

In addition, you can use the NPM Package Management dialog to search the repository and install packages.

Package Management in npm package management in VS

And the package installation process itself ...

Module installation

Instead of the node_modules folder and module files, we see a beautiful hierarchy of nodes in Solution Explorer.

Modules in Solution Explorer

Note : I like this approach. It has potential, and visualization of modules, by analogy with links in .NET projects, simplifies understanding dependencies.

There are also other interesting components. For example, the REPL interactive window, the traditional web application publishing wizard familiar to ASP.NET developers. You can publish apps to Azure using either Git or the Visual Studio Publishing Wizard.

In addition, you can perform remote debugging of a node.js running with remote debugging options on another machine.

Remote debugging node.js application

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

Once again, we note that remote debugging of applications in Visual Studio is available for node.js running on any server OS.

Conclusion


I am impressed with how intensely Visual Studio is developing and turning into a comfortable and modern development environment.

Node.js Tools for Visual Studio is an open source project distributed under the Apache license. The NTVS team is looking forward to receiving feedback from the community in the form of comments, suggestions and bug reports . The alpha version is still available, but over time NTVS will get even better. Look at it with your own eyes. Many thanks to all the project participants!

Source: https://habr.com/ru/post/203170/


All Articles