-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
53 lines (38 loc) · 1.26 KB
/
server.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var express = require('express');
const cors = require('cors'); // Import the cors middleware
var app = express();
// Use the cors middleware with default options (allows requests from any origin)
app.use(cors());
app.get('/api/data', function (req, res) {
var sql = require("mssql");
// config for your database
var config = {
user: 'dmad',
password: 'myPass',
server: 'localhost',
database: 'project' ,
options: {
trustedConnection: true,
encrypt: true,
enableArithAbort: true,
trustServerCertificate: true,
}
};
// connect to your database
sql.connect(config, function (err) {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
// query to the database and get the records
request.query('select * from mixtape', function (err, recordset) {
if (err) console.log(err)
// send records as a response
//res.send(recordset);
const data = recordset;
res.json(data);
});
});
});
var server = app.listen(5000, function () {
console.log('Server is running..');
});