How To Connect SqlServer with Node.js In AWS(Amazon Services) -Part1

This proof of concept is created to check how node.js works with sqlserver database.

There are many drivers available to support sqlserver in node js. I have created this poc with most usable driver “MSSQL” and you can check available drivers by executing below command in nodejs environment.

Command: npm find sqlserver

Above command gives all available sqlserver drivier for node.js.

There are following steps to configure node.js with sqlserver and you have to create same steps in your machine to run this sample.

Step 1:  install node js package for sqlserver by using below command:

“Npm install mssql “

Step2: Create Sa login in sqlserver and also create I have create sample database with name “EmpDb” with table name “Employees” with some records.

step2 step2-2 step2-3

Step3: Create below code in node.js application:

var sql = require(‘mssql’);

var config = {

user: “sa”,

password: “password@123”,

server: “Localhost”, // it can be servername if connecting directly with sqlserver or can be replace by RDS end point

example: ‘;dbname= EmpDb

database: “EmpDb”


function GetEmp() {


var connection = new sql.Connection(config);

var request = new sql.Request(connection); // or: var request = connection.request();

console.log(“step1 end”);

connection.connect(function (err) {

if (err) {




request.query(“select * from Employees”, function (err, recordset) {

if (err) {



else {








Step4: Now run the application and below output well come:


Note: I have used only select statement in this sample,If you want to perform update and delete then you can also use these operations.