Getting Started With Node.js Development in Visual Studio

Setup Environment on Windows machine for Node.js Development [Set up Sublime Text]

Yes you love node.js. You love event-driven development and yes multi-threading is old fashioned now. Your new-found love is asynchronous. Asynchronous everything, even reading a file system. As we all know Microsoft loves developers. So in a build they decided to provide node.js development support in Visual Studio 2012 and Visual Studio 2013.

In this article we will take a step-by-step look at setting up Visual Studio for node.js development. Use the following procedure to do that.

Step 1: Download and install Node.js from node.js.

Step 2: Next download and install Node.js for Visual Studio from:

Node.js Tools for Visual Studio

You need to ensure that you select the correct option to download. I will install Node on Visual Studio 2012.

install Node on Visual Studio 2012

After successful installation you will get the following confirmation message of successful installation.

successful installation

After installation of the preceding pieces you are good to go and start developing Node.js in Visual Studio. On launching Visual Studio in the JavaScript language category, you will get various project templates related to Node.js as in the following:

project templates related to Nodejs

There are five different project templates available.

project templates

You can create a Node.js application web based by selecting a Blank Node.js Web application project template.

Blank Nodejs

On successful creation of the project you will get the following files in the project. Solution Explorer will look as in the following:

Solution explorer

"server.js" will contain the code and entry point of the application. By default server.js contains the following code:

default serverjs

You just need to press F5 to run with the debugger or Ctrl+F5 to run without debugging. This default code will give you following output in the browser:

default serverjs

And whereas the debugger is listening on port 5858.

debugger

So we have experienced that working with Node.js in Visual Studio is very smooth. You just need to press F5 to run the application and we can use a breakpoint and debug the code. As you see in the following image the breakpoint is being hit.

breakpoint

You will also find that intellisense will work as expected. There is complete support of intellisense for Node.js.

intellisense for Nodejs

Another thing you will notice is that the Node.js debugger supports a complete stack trace.

stack trace

Exporting existing Node.js project

You can create an existing Node.js project from an existing Node.js project by creating a project and choosing the template "From Existing Node.js code".

Existing Nodejs

On the next screen you need to browse to the existing project folder. You can also select files types to be included. After providing these two inputs click on "Finish".

Browse to existing project folder

You will find that the existing project has been exported to the new project.

In this way you can set up Visual Studio 2012 to work with Node.js development. I hope you find this article useful. Thanks for reading.

Up Next
    Ebook Download
    View all
    Learn
    View all