MaxBeauchemin
1/3/2018 - 2:39 PM

Node.js SQL Select

How to communicate to a SQL database using Node.js

const sql = require('mssql');

console.log('loaded');

//Note: use two backslashes for a server with an instance name i.e. server\\instance
var connection = {
	user: "######",
	password: "######",
	server: "######",
	database: "######"
};


var queryStr = "SELECT * FROM Converting.Assets";

// connect to your database
sql.connect(event.Connection).then(function () {

  var request = new sql.Request();

  request.query(event.Query).then(function (data) {
    sql.close();
    console.log(data.recordsets[0]);
  }).catch(function (error){
    sql.close();
    callback(error);
  });
}).catch(function (error){
    callback(error);
});