-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbConfig.js
More file actions
32 lines (29 loc) · 790 Bytes
/
dbConfig.js
File metadata and controls
32 lines (29 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require('dotenv').config();
const sql = require('mssql');
const config = {
server: process.env.DB_SERVER || 'sqlserver',
authentication: {
type: 'default',
options: {
userName: process.env.DB_USER || 'sa',
password: process.env.DB_PASSWORD || 'password@Password',
},
},
options: {
database: process.env.DB_NAME || 'master',
encrypt: true,
trustServerCertificate: true,
connectTimeout: 30000 // 30 seconds timeout for connection
},
};
const poolPromise = new sql.ConnectionPool(config)
.connect()
.then(pool => {
console.log(pool);
console.log('Connected to SQL Server');
return pool;
})
.catch(err => console.error('Database Connection Failed! Bad Config: ' + config, err));
module.exports = {
sql, poolPromise
};