Webstorm | Connecting to SQL server using the 'mssql' npm package

I am trying to connect to SQL server from my nodejs based test framework running in Webstorm.

Though I am able to run the code independently outside of webstorm from the terminal using the command -

node <filename.js>

However when I run my code through Webstorm, the connection is not established.

Code which runs successfully outside of webstorm:

===============================================================================

Code which runs successfully outside of webstorm:

===============================================================================

const sql = require('mssql');

console.log('Estabilishing SQL DB connection...1');

const config = {
user: "",
password: "",
server: "",
database: "",
port: 1433
};

function getdata()
{
var conn = new sql.Connection(config);

console.log('config ', config);
console.log('conn ', conn);
console.log('Estabilishing SQL DB connection...2');

conn.connect().then(function () {
console.log('1');
var req = new sql.Request(conn);
req.query('select count(*) as TablesCount from sys.tables').then(function(recordset){
console.log('2');
console.log(recordset);
conn.close();
}).catch(function (err) {
console.log('3');
console.log(err);
conn.close();
})
}).catch(function (err) {
console.log('4');
console.log(err);
})
}

getdata();

===============================================================================

Code which does not works from within Webstorm

===============================================================================

var fs = require("fs");
var await = require('await');
var async = require('async');
var yaml = require('js-yaml');
var world = require('../support/world.js').World;
var worldInstance = new world();
var db = require('../step_definitions/db.js');

var mssqlmethods = function () {

this.Given(/^I connect to SQL DB$/, function () {

var sql = require('mssql');

console.log('Estabilishing SQL DB connection...1');

const config = {
user: "",
password: "",
server: "",
database: "",
port: 1433
};

var conn = new sql.Connection(config);

console.log('config ', config);
console.log('conn ', conn);
console.log('Estabilishing SQL DB connection...2');

conn.connect().then(function () {
console.log('1');
var req = new sql.Request(conn);
req.query('select count(*) as TablesCount from sys.tables').then(function(recordset){
console.log('2');
console.log(recordset);
conn.close();
}).catch(function (err) {
console.log('3');
console.log(err);
conn.close();
})
}).catch(function (err) {
console.log('4');
console.log(err);
});
};
module.exports = mssqlmethods;

===============================================================================

Webstorm information

===============================================================================

WebStorm 2017.2.4
Build #WS-172.4155.35, built on September 11, 2017
JRE: 1.8.0_152-release-915-b11 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.12.6

===============================================================================

0
1 comment

>Though I am able to run the code independently outside of webstorm from the terminal using the command -

node <filename.js>

However when I run my code through Webstorm, the connection is not established

 

sounds strange - as all webstorm does is running Node.js, passing the .js file to it. What does your Webstorm run configuration look like? please attach screenshots of your run configuration and your run console

0

Please sign in to leave a comment.