It should come as no surprise to you that Node.js is quickly becoming recognized as a powerful and performant programming language. It seems like every week a new corporate behemoth is moving at least some parts of their application infrastructure over to node. Last week was no exception with Microsoft throwing its weight behind the language by releasing support for Node.js inside of its popular integrated development environment called Visual Studio.
Developers seem to either love or hate Visual Studio and this comes down mainly to the application that they are trying to write. For instance, most .NET developers absolutely love Visual Studio and others seem to prefer a lighter weight approach to IDE(s) with many preferring sublimetext. In this blog post, we will take a look at the Node.js integration with Visual Studio which in turn may intrigue you enough to take a look at this IDE for node.js development.
Given that a lot of node.js developers may not have experience with Visual Studio or even Windows for that matter, this post will also cover the installation and configuration of node.js and Visual Studio on the Windows operating system.
Step 1: Install Windows
The first thing we need to do in order to take advantage of the node.js capabilities inside of Visual Studio is to have the windows operating installed on our machine. I typically use Mac OSX for my development so I decided to install Windows 8.1 inside of a Parallels Virtual Machine. If you do not have a license for Parallels, you could also use VirutalBox, VMWare, or even use bootcamp to run Windows natively on your OSX hardware.
If you are a Linux user, I suggest installing Windows inside of a VirtualBox VM.
Step 2: Install the StrongLoop Suite
Once you have downloaded the current version of StrongLoop Suite for your operating system, execute the installer and follow the onscreen instructions for installing the package.
This will install the StrongLoop Suite package including the core Node.js runtime for us to use for our applications.
Step 3: Testing our node distribution
Now that we have our operating system and StrongLoop installed, let’s verify that our suite is working correctly by creating a sample application to verify the installation. In order to create our sample application, open up the command prompt inside of Windows by clicking the start button and then entering in *cmd*. This will open up the Windows shell prompt. Once you are on the shell prompt, execute the following commands:
$ cd c:\
$ mkdir code
$ cd code
$ slc example
After you enter in these commands, a sample application will be created for you in the *c:\code\sls-sample-app\* directory. Change to that directory and start up the node.js server:
$ cd c:\code\sls-sample-app\
$ slc run .
If everything worked correctly, you should see a message similar to the following:
StrongLoop Suite sample is now ready at <a href="http://0.0.0.0:3000">http://127.0.0.1:3000</a>
Pull the application up in your web browser and ensure you see the following:
Step 4: Install Visual Studio
Now that we have the StrongLoop Suite installed and verified, we can install Visual Studio. Point your browser over to the official download site for Visual Studio and select the edition you want to install. I will be taking advantage of the 90 day free trial for Visual Studio Premium 2013 during this blog post. Select the package you wish to use and click on the *Install now* option.
This will allow you to download the installation program titled *vs_premium.exe*. Once you have this downloaded, execute the installation and follow the onscreen instructions. Depending on the speed of your Internet connection, the installation process could take a while to complete. For the full installation, it will require roughly 7gb of disk space on your computer.
Step 5: Install Node.js Tools for Visual Studio
Now that we have Visual Studio installed and working correctly, it is time to install NTVS (Node.js Tools for Visual Studio). In order to do this, close down Visual Studio, if you have it running, and point your browser over to the official NTVS download site. Once you download the correct package for your Visual Studio installation, I am using Visual Studio 2013, begin the installation process.
Step 6: Verify NTVS installation
At this point, we should have the StrongLoop Suite, Visual Studio 2013, and NTVS installed and running correctly. To verify this, open up Visual Studio Node.js interactive window by clicking on View->Other Windows->Node.js Interactive Window and enter in the following commands:
As you can see in the above example, we set a String variable and then verified the Node.js runtime that Visual Studio is using. In this case, it is using the StrongLoop Suite Node.js package that we installed in a previous step.
Step 7: Creating and running a StrongLoop Suite project
After we have our express created, let’s go ahead and run the application by clicking on the run button in the top toolbar inside of the IDE. I have Chrome set as my default browser so the application will be running inside of that browser.
After clicking this button, your default browser should launch showing the newly created express application. You will also notice that the node runtime being used is the one from StrongLoop Suite via the popup command prompt that displays your logs.
Step 8: Debugging and intellisense
You may have noticed in the above step that the node runtime was actually running in debug mode. At this point we can add breakpoints inside of our source code and the IDE will break at that particular line to allow us to step through, or in, the code to help us track down issues.
Another great feature of the NTVS suite is that ability to have code completion on our Node.js source code. In order to activate this feature, just begin editing your source code and when you hit the . operator, all available functions will be presented to you. You can also hit control-space to pull up Intellisense as well.
Although NTVS is in Alpha state, it is already providing one of best IDE integrations for Node.js available today. Granted, I am not a huge fan of Visual Studio but I am finding that the benefits I have already seen using this IDE is outweighing my negative thoughts about this environment. I am OSX user but I am envisioning that I will be spending more and more time inside of Window VM in the coming months to work on Node.js code.
- Register for our “Working with LoopBack Models and Data” Webinar.
- Want to read more articles like this? Check out “Using a Digital Ocean Droplet for On Demand Node.js Mobile Backend”, “How-to: Heap Snapshots and Handling Node.js Memory Leaks” and “Using Express.js for APIs”.
- Do you want to keep up on the latest Node.js news and developments? Sign up for In the Loop, StrongLoop’s newsletter.
- Ready to make your own Node.js product? We’ve made it easy to get started. Sign up and get access to a pre-configured Cloud Workspace, downloads or builds for your favorite cloud.