NTVS for Node.js : Use Visual Studio as Node.js IDE

Yes, Now you can convert your Visual Studio to Node.js IDE thanks to NTVS 1.0!

First of all let us see what is Node.js?
Node.js is an open source, cross-platform runtime environment for server-side and networking applications.

Node.js applications are written in JavaScript and can be run within the Node.js runtime on OS X, Microsoft Windows, Linux, FreeBSD, NonStop, IBM AIX, IBM System z and IBM i.

Its work is hosted and supported by the Node.js Foundation,a Collaborative Project at Linux Foundation.
More details can be found here.

Now What is NTVS?
NTVS stands for “Node.js Tools for Visual Studio” which have released its first version in March 2015.

How to get NTVS 1.0?
You can download it from here.

What to do after downloading?
Click on the .msi file you got in your download folder and you will see below screen.


After finishing installment process open your Visual Studio and you can search for Node.js file as shown in below image.


By clicking on Blank Node.js Web Application Below type of window will appear which would be your first Node.js in Visual studio.


From above image you can see it also supports IntelliSense.

Ok, What about Debugging?
Well you can even debug your code as shown in below image:-


Great, Now tell me does it provide Windows Azure Support?
Yes it does.


But we MUST include the “node_modules” folder into project to ensure it could be uploaded along with our codes if we use Web Deploy or FTP to publish.


Anything like Visual Studio Command Window for Node.js?
It has its own Node.js Interactive Window as shown in below image:-


Awesome, isn’t it? Now let us run the application and This action will automatically start the browser on the local Web server, selecting port 1337.

we would get below result :-

NTVS is now on GitHub! which you can find here.

So, enjoy Node.js but in Visual Studio Style!


C# 6.0 : Something new on it’s way

As we know C# 6.0 is about to come with Visual Studio 2015, Let us see some of the awesomeness which will be gifted to us with C# 6.0

First of all Let us start with the part which a developer always gets, even after taking lots of care, is Exceptions!!

1) Conditional Catch Blocks

As a developer there might be a need that we require some conditions on Try.. catch block to catch some particular type of exception.

For that earlier we needed to do like below :-


 catch (Exception ex) 
 if (ex.InnerException.Message == "Parameter Error") 
throw; } 

Now in C# 6.0 developers can now do the same by adding a if test to the catch statement.

 catch (Exception ex) when (ex.InnerException.Message == "Parameter Error")
 ...error handling code...

2) Wait over for “await” in Catch Block

Have you ever wanted “await” in catch block? Your search is over because C# 6.0 would allow you to add await keyword in catch block.

Earlier :-

 result = await wc.DownloadStringTaskAsync( new Uri( "http://badurl" ) );
 downloadSucceeded = true;
 downloadSucceeded = false;

if (!downloadSucceeded)
 result = await wc.DownloadStringTaskAsync( new Uri( "http://fallbackurl" ) );


 //Do something
catch (Exception)
 await Logger.Error("exception logging")

3) Easy property initialize-rs

As you know till now if we want to initialize properties we always needed a constructor and then we initialize our auto incremented property as below :-


public int Id { get; set; }
public YourClass()
Id = 1;

In C# 6.0, you can also initialize that property to some constant value in the same statement, like this:


public int Id { get; set; } = 1;

4) Awesome Index Initializers

Suppose you want a Dictionary object for let us say key value pair of int and string so you would write something as below :-


Dictionary<int, string> students = new Dictionary<int, string>()
 { 1, "Student1" },
 { 2, "Student2" },
 { 3, "Student3" },

C# 6.0 gives you a new syntax that saves a few keystrokes but, more importantly, makes the resulting code easier to read by eliminating some curly braces and leveraging the equals sign. The new syntax looks like this:


Dictionary<int, string> newRomanNumerals = new Dictionary<int, string> ()
 [1] = "Student1",
 [2] = "Student2",
 [3] = "Student3"

5) String Interpolation

It can be looked at as an improvement to the String.Format functionality where, instead of the place holders, you can directly mention the string expressions or variables.
Sometimes when we use String.Format(), the numbered placeholders like {0}, {1}, {2}, etc. caused the problem (especially when you use more placeholders) due to arguments to be supply in the same order.


var statement = string.Format("This is one of the features of {0}", lng.CurrentLanguage);


var statement = $"This is one of the features of {lng.CurrentLanguage}";

6) More Power to Static Classes

Till now whenever we reqired to use Static objects we needed name of the class before the object like below :-



C# 6.0 allows us to import the Static classes and use the static members directly without class name.


using YourClass;

7) OUT Parameter Declaration

It was always required for OUT paramater to be declared before the use of that parameter as below :-


DateTime dateTimeValue;
 DateTime.TryParseExact(parameterValue, "MM-dd-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTimeValue);

C# 6.0 allows you to declare the OUT parameter during the method call, as shown below.


DateTime.TryParseExact(parameterValue, "MM-dd-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTimeValue);

8) Null-conditional operators

What if you want to check for null in C#?

Well suppose i have some varaible named result and i want to check for null then:-


var requiredResult = result == null ? 0 : result.myResult;

C# 6.0 introduces Null-conditional (?.) operator which works on top of conditional (?:) operator to provide the much easier access to check the NULL values.


var requiredResult = result?.myResult;

9)  Roslyn—A New Compiler for C#

Yes, new compiler for C# as well as for VB which is open source and can be found at Github.

So, I hope it would be helpful to you and I will add more as soon as i get to know more and more beauty of C# 6.0!

Till then Happy Coding!

NodaTime : A Nuget Package for Date and Time

It has been a while since i wrote last post but i am back with one more Nuget package which is NodaTime.

Many of you have always worked with Date time or time zone in your current project or in past and if you try to recall you might have faced some problems because while doing time and timezone related programming you would know how much headache it can be.

NodaTime tries to make that process a little bit better and it is written by the famous Jon Skeet.

Let us say more in details like Noda Time is an alternative date and time API for .NET. It helps you to think about your data more clearly, and express operations on that data more precisely.

To install NodaTime  , run the following command in the Package Manager Console :-


Now the question comes why do we need NodaTime? or What’s wrong with DateTime anyway?

Well The standard DateTime data type in .NET is not setup properly to deal with time zones. The DateTime type does not allow you to define a date and time in a specific time zone.

And Jon Skeet has written more on this which is here :- what-wrong-with-datetime-anyway

Let us see some of the examples :-

 //Instant represents time from epoch
 Instant now = SystemClock.Instance.Now;

// Convert an instant to a ZonedDateTime
 ZonedDateTime nowInIsoUtc = now.InUtc();

// Create a duration
 Duration duration = Duration.FromMinutes(3);

// Add it to our ZonedDateTime
 ZonedDateTime thenInIsoUtc = nowInIsoUtc + duration;

// Time zone support (multiple providers)
 var london = DateTimeZoneProviders.Tzdb["Europe/London"];

// Time zone conversions
 var localDate = new LocalDateTime(2012, 3, 27, 0, 45, 00);
 var before = london.AtStrictly(localDate);

Well there is whole website made for NodaTime and there are lots of scenarios mentioned which we cant include all here so better visit this for more examples:-


From a unit testing perspective NodaTime makes the process also a bit easier as it exposes an IClock interface to get the current time, which can be mocked or you can even use their own FakeClock class to assist with testing.

For that you need to run the following command in the Package Manager Console:-


NodaTime is also available in Git hub which you can find here.

So, finally i will suggest to use NodaTime not just for expressiveness and correctness of your code but also because it is just Awesome!

Happy Coding!


Create a free website or blog at WordPress.com.

Up ↑