I am using Knex.js
to connect Sql server
using Node.js
. Here is what i tried so far
npm init
npm install knex --save
npm install mssql -g
nodemon index.js
and index.js
file have
var knex = require('knex')({
client: 'mssql',
connection: {
user: 'sa',
password: 'Password@123',
server: 'manikant/SQLEXPRESS',
database: 'myDb' ,
options: {
port: 1433
}
}
});
app.get('/getData',(req,res)=>{
const data = {};
knex.select("*").from("usr")
.then(function (depts){
depts.forEach((dept)=>{ //use of Arrow Function
console.log({...dept});
data = {dept}
});
}).catch(function(err) {
console.log(err);
}).finally(function() {
knex.destroy();
});
res.json({data})
})
But getting errors message: 'Failed to connect to manikant/SQLEXPRESS:1433 - getaddrinfo ENOTFOUND manikant/SQLEXPRESS',
code: 'ESOCKET'
},
TCP/IP
protocol is enabled on port 1433
and Sql server browser
is running.
followed similar question on SO
Note:- Able to connect with java application.So seems like problem with knex only.