1const sql = require('mssql')
2const query=`select * from table`;
3config = {
4 database: "dbname",
5 // can keep these option required with latest version of mssql npm package
6 options: {
7 enableArithAbort: true,
8 encrypt: true,
9 rowCollectionOnRequestCompletion: false,
10 },
11 parseJSON: true,
12 password: "password",
13 port: port, // if youe database running on difrent port then 1433
14 server: "server ip or name",
15 user: "usenme",
16 };
17
18
19sql.on('error', err => {
20 // ... error handler
21})
22
23sql.connect(config).then(pool => {
24 return pool.request()
25 .query(query)
26}).then(result => {
27 console.log(result.recordset)
28}).catch(err => {
29 console.log(err)
30});
31