Bagaimana Node JS mengakses SQL Server

SQL Server May 15, 2018

Dear Pembaca Setia,

Berikut akan penulis bagikan pengalaman penulis membaca membaca data di SQL Server lewat Node JS.

Kali ini penulis menggunakan library tedious sebagai driver-nya, dan Microsoft Visual Studio 2017 Community Edition sebagai IDE-nya.

Script berikut dapat digunakan untuk mengakses menggunakan SQL Query biasa ataupun mengakses Stored Procedure.

Driver Installation

npm install tedious

Node JS Script

'use strict';

var Connection = require('tedious').Connection,
    Request = require('tedious').Request,
    TYPES = require('tedious').TYPES;

var sqlQuery = "EXEC [DUMMY_SP] '" + "EAP-" + "'";
//var sqlQuery = "SELECT * FROM myTable";

var connection = new Connection({
    server: '',
    userName: 'sa',
    password: 'password',
    options: {
        database: 'myDB'

connection.on('connect', function (err) {
    var request = new Request(sqlQuery, function (err, rowCount, rows) {
        if (err) {
        } else {
            //console.log(rowCount + ' rows');


    // Display retrieved row
    request.on('row', function (columns) {
        columns.forEach(function (column) {
            if (column.value === null) {
            } else {



  1. Tedious
  2. Sample
  3. IDE

Demikian tutorial kali ini. Salam koding.


Eldest Pasirula

Software Engineer, Blog Writer, $TSLA follower

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.