Node.js Development Part 2 – Visual Studio and Node.js

In this second part of my node.js development investigation we will look at using Visual Studio as a development environment.

To begin open Visual Studio and select New Project.

New Project
New Project

From the available project categories select Web and then from the template select ASP.NET Empty Web Application. Select a location for the project and then give it an appropriate name.

Create Empty Web Application
Create Empty Web Application

You should now be faced with an empty web project in the Visual Studio IDE.

Visual Studio Solution
Visual Studio Solution

Delete all default files/folders that were created with the project. Now create a JavaScript file called app.js with the following contents:

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

This is the sample code from nodejs.org homepage that creates a basic webserver that will respond to http requests on port 1337 with the plain text Hello World.

App.js
App.js

Next the Visual Studio project needs to be configured to start up node.js when run so we can test the webserver just created.

Project Properties
Project Properties

From the top menu select DEBUG and Start Without Debugging or launch with Ctrl + F5

Run Project
Run Project

A command window should now open with the address of the running server.

Command Window
Command Window

Copy this address into a browser and voila the page is served by node.js.

Running In Browser
Running In Browser

You now have a running server that is responding to requests and serving responses over http. At this point there is little you can actually do with this, the next posts will cover adding packages to serve CSS files and HTML pages in a structured way, connecting to a database to serve content and running node.js under IIS stay tuned!

Node.js Development Part 1 – Installing Node.js

Node.js is a very fast application platform for building network applications, it is free to use for both personal and commercial applications. A simple webserver can be written in a few simple lines of code and there are currently over 30,000 Node Package Modules to extend the core functionality.

Applications are written in JavaScript which enables deployment across a large number of platforms. Installers/binaries are available for Windows, Mac, Linux and Sun OS with source also available for download. This series of posts will be focused on the Windows platform as this is where I do a majority of my work and will include advice on using Visual Studio 2012 as a development tool.

To install node.js simply browse to:

http://nodejs.org

and click the Install button in the centre of the page. This will download the Windows x64 msi installer.

After the installer has downloaded run the msi and accept the defaults as shown below.

Setup wizard
Setup wizard
End User License Agreement
End User License Agreement
Destination Folder
Destination Folder
Custom Setup
Custom Setup
Installation
Installation
Installing
Installing
Completed
Completed

And that’s it node should now be successfully installed, the next part will cover testing the installation by setting up a Visual Studio web project and creating a basic webserver in node.js.

CloudFlare

Recently I discovered a new service CloudFlare which I have been testing on this blog, I stumbled across it while visiting another site that had an outage. CloudFlare works by adding an extra layer between your website and the rest of the internet. It provides CDN, optimzation, security and analytics as well as offering integration with other apps.

The best feature of CloudFlare is that it has a free tier so you get to experiment with many of the features without having to sign up for a lengthy contract or even get your credit card out. Since setting it up I have created a deliberate outage and then when testing, yes my site was still available, outstanding!

The ability to combine javascript files into a single request and minify HTML, CSS & javscript files to reduce requests and bandwidth alone is worth signing up for. I have now implemented it across all the sites I manage without any issues, just benefits.

My recommendation give it a try today, you may be suprised and if you don’t like it just turn it off again!

I am in no way associated with CloudFlare other than being a free user.

http://www.cloudflare.com

SharePoint 2010 – User Profile Synchronisation Issues

After struggling with even getting the User Profile Synchronisation service set up within SharePoint 2010 my syncs were failing every time. The ULS and event logs both let me down by not providing anything but generic messages.

Finally through much Google searching I found not the solution but a way to diagnose issues I was not aware of. The MIIS client, Synchronisation Service Manager. This tool can be found already installed (!) in %programfiles%\Microsoft Office Servers\14.0\Synchronisation Service\UIShell\miisclient.exe

Running this brings up a window with a log of all User Profile synchronisation attempts and more importantly their associated error messages as shown below:

MIIS Client
MIIS Client

This enabled me to quickly decide where the issue was and then resolve it, hope it saves someone else a few hours of searching for User Profile Synchronisation error messages!

Managed Service Accounts

I have been setting up a new development server Hyper-V VM and having trouble with configuring managed service accounts which in principle sound like a good way to go. After much struggling and frustration with the (pretty poor) technet doco I finally found an excellent blog post and tool which got me back on track.

The blog post can be found at the follow link below:

http://sqlmate.wordpress.com/2012/04/16/managed-service-accounts-with-microsoft-sql-server-2012/

And the tool can be downloaded (for free!) here:

http://cjwdev.co.uk/Software/MSAGUI/Download.html

 

If you haven’t used managed service accounts before or have been struggling like me I recommend you check out the links!