Node.js And AngularJS With SQL Server

Introduction

What Node.js is

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 and IBM i.

Advantages

  1. Web development is done in a dynamic language (JavaScript) on a VM that is incredibly fast (V8). It is much faster than Ruby, Python, or Perl.
  2. Ability to handle thousands of concurrent connections with minimal overhead on a single process.
  3. JavaScript is perfect for event loops with first class function objects and closures. People already know how to use it this way having used it in the browser to respond to user-initiated events.
  4. Many people already know JavaScript, even people who do not claim to be programmers. It is arguably the most popular programming language.
  5. Using JavaScript on a web server as well as the browser reduces the impedance mismatch between the two programming environments that can communicate data structures via JSON that work the same on both sides of the equation. Duplicate form validation code can be shared between server and client and so on.
Installation
  1. Install npm (https://nodejs.org/)
  2. Install Visual Studio 2012
  3. Install SQL Server 2008 r2
  4. NTVS 1.0 RC 2 Visual Studio 2012(https://nodejstools.codeplex.com/releases/view/612573)
  5. Use Angular js library

Procedure

Create a table in your database and insert a row as in the following:

  1. CREATE TABLE [dbo].[Nodejs](  
  2.   
  3. [Id] [int] IDENTITY(1,1) NOT NULL,  
  4.   
  5. [Text] [nvarchar](50) NULL,  
  6.   
  7. CONSTRAINT [PK_Nodejs] PRIMARY KEY CLUSTERED  
  8.   
  9. (  
  10.   
  11. [Id] ASC  
  12.   
  13. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ONON [PRIMARY]  
  14.   
  15. ON [PRIMARY]  
Insert a row into the table as in the following:
  1. INSERT INTO [IMS1.0].[dbo].[Nodejs]  
  2.   
  3. ([Text])  
  4.   
  5. VALUES  
  6.   
  7. ('Hello word!!')  
  8.   
  9. GO  
Open the project in Visual Studio and you will see the following folder structure:

How to install all packages

Right-click on npm and select Install New npm Packages.

 

Open the api.js file and set the Microsoft SQL database credentials and database name.

 

Enter the following query:

 


Please download the code and use the following procedure and run the code.

Output Window 
 
 

Up Next
    Ebook Download
    View all
    Learn
    View all