Dealing with Node.js and Microsoft SQL Server: Part-2

In the previous post we did an overview of the different Node.js drivers for Microsoft SQL Server. There was a comparison between different modules for SQL Server and were considered and their advantages and disadvantages

Developers who work mainly with Node.js and open source technologies have experience how to build and debug Node applications. People, dealing with Microsoft SQL Server usually have more experience with Visual Studio and Microsoft platforms. It is also possible to use SQL Server Data Tools with VS

Node.js Tools for Visual Studio:

Node.js Tools for Visual Studio is a good solution if you want to get advantages from both – Node.js and SQL Server ( it is not a requirement – it just make development suing both technologies easier ).

The first public Alpha is released in November, 2013. Beta 1.0 is available from April, 2014 and in July is relapsed Beta 2.0

Node.js Tools for Visual Studio, aka NTVS, is a free/OSS plug-in that turns Visual Studio into a Node.js IDE. It only takes a few steps to get setup so let's jump right into it.

Node.js Tools allows you to create projects using the Visual Studio project system. Project files (.njsproj) reference all the source and content files associated with your project, showing them all in the Solution Explorer window and enabling NTVS to most efficiently work with your files.

It is possible to create .NET library, implementing any queries, that you can create in .NET with ADO.Net and after that to import this library in your Node.js project and invoke methods using Edge.js module.

Import the .Net assembly and use it’s API in Node.js + Edge application ( you should specify the method, that will be invoked )

1:// Set up the assembly to call from Node.js

2:var querySample = edge.func({

3: assemblyFile: 'EdgeSampleLibrary.dll',

4: typeName: 'EdgeSampleLibrary.CSSample',

5: methodName: 'Invoke'

6: });

Invoke a specified method from Node.js

1:// This is the data we will pass to .NET

2:var data = { pageNumber: 2, pageSize: 3 }

3:

4:// Invoke the .NET function

5: querySample(data, function (error, result) {

6: ....

7: });

The use of Node.js, Visual Studio and SQL Server makes it easy and flexible the creation of multiplatform data centric applications (on premises and in the cloud).

In the next part of this article you can learn how to use Node.js module for Microsoft SQL Server / Azure SQL Database in Microsoft Azure applications (Azure Web Sites and Azure Cloud Services ). We will take a look at the best practices and cover different use cases.

If you want more information about how to use Microsoft SQL Server & Node.js feel free to contact me at mmateev@infragistics.com