HTML5 Zone is brought to you in partnership with:

My name is Bruno Terkaly and I am a Developer Evangelist in Northern California. Over the past few months I have been presenting a wide variety of demos and slides highlighting the wealth of new features in Visual Studio 2008. Bruno is a DZone MVB and is not an employee of DZone and has posted 51 posts at DZone. You can read more from them at their website. View Full User Profile

Getting Started With Node.js and Visual Studio

01.27.2014
| 6702 views |
  • submit to reddit

This is first in a series of post dedicated to helping you get up to speed with Node.js. This post will not make any attempts to explain why node is interesting or why you should learn it.

There are many ways to learn node and many developer tools to work with. Visual Studio is the market leader when it comes to integrated development environments. So that’s what I’m going to use.

Even if you know node, this post will have value in that it will show you how to work with node using Visual Studio.

Installation

You can start by going to CodePlex to download the necessary installation files.

This link and how to get started: 
https://nodejstools.codeplex.com/releases/view/114437

As of this writing the tools are in the early stages. The installation file can be found here:

image001

Figure 1 - CodePlex installation/MSI file

The Visual Studio node extensions will be registered enabling you to create node projects from within Visual Studio.

image002

Figure 2 - The node Installer for Visual Studio 2013

Your first basic application

Let’s begin with the most simple application possible. Start Visual Studio and go to the file menu and choose new project. Notice there is a JavaScript template, allowing us to select Blank Node.JS Web Application. I will choose HelloWorld.js.

image003

Figure 3 - File/New Project/Blank Node.js Web App

Solution Explorer will contain the most rudimentary aspects of your node application. As we move through this tutorial we will add additional packages.

image004

Figure 4 - Solution Explorer

Visual Studio automatically provides the “hello world” message.

server.js

var http = require('http'); 
var port = process.env.port || 1337; 
http.createServer(function (req, res) { 
    res.writeHead(200, { 'Content-Type': 'text/plain' }); 
    res.end('Hello World\n'); 
}).listen(port); 

(Code Snippet - server.js)

Note: We will quickly address that Visual Studio supports Intellesense.

Intellisense

The nice thing about Visual Studio is that Intellisense is available, dramatically simplifying coding.

image005

Figure 5 – Intellisense

Notice in the figure above I just typed in http plus a period and the system automatically provided on the methods and properties relevant for http.

Require

You can also use the require() method to load and cash JavaScript modules, which are localized memory spaces that contain singletons and class definitions. We will talk more about this capability in future modules. For those of you with some nodeexperience, you’ll appreciate Visual Studio’s capability to list locally installed default modules.

Simply type in require (.

image006

As you can see Visual Studio will automatically provide a list of available modules that are part of the default installation.

Running our project

One of the great things about Visual Studio is its ability to run with a simple F5 key. This action will automatically start the browser on the local Web server, selecting port 1337.

Figure 6 - Visual Studio showing available modules

image007

Figure 7 - Running project

Notice in the figure above that everything just works and that hello world easily shows up in the browser.

Summary

In this post we looked at the minimum knowledge you will need to move forward. We started with the discussion of how tointegrate node.js with Visual Studio. We looked at some of the built-in niceties that Visual Studio provides, such asIntelliSense. We then ran the project with the simple F5 key.

Published at DZone with permission of Bruno Terkaly, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)