I am using the latest versions of node, express and mssql module. I am trying to connect to the local instance of sql server 2014 using express.js.
I am using mssql module and callbacks mechanism from the official documentation.
I have tried:
const express= require('express');
const app= express();
const mssql= require('mssql');
app.get('/', (req, res) =>
{
const configuration=
{
name: "default",
host: 'localhost',
database: 'HimHer',
user: '',
password: '',
port: 1433
}
new mssql.connect(configuration, error =>
{
new mssql.Request().query('Select * from Users', (err, dataset) =>
{
if(err)
{
console.log(err);
res.send(err);
return;
}
else
{
console.dir(dataset);
res.send(JSON.stringify(dataset));
return;
}
});
});
mssql.close();
mssql.on('error', err =>
{
console.log(err);
});
});
app.listen(5000, () =>
{
console.log('Listening to requests on port 5000');
})
I want it to be connected to the database.