forked from coryhouse/js-dev-env-demo-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (35 loc) · 1.18 KB
/
index.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
var express = require('express');
var cors = require('cors');
var sql = require('mssql');
const app = express();
app.use(cors());
app.set('port', (process.env.PORT || 5000));
app.get('/', function(request, response) {
response.send('Hello Mishu!')
});
const config = {
user: 'mishu',
password: 'dorina-Ursu0488',
server: 'mishuserver.database.windows.net', // You can use 'localhost\\instance' to connect to named instance
database: 'js-dev-env',
options: {
encrypt: true // Use this if you're on Windows Azure
}
}
sql.connect(config);
app.get('/users', function(req, res) {
const request = new sql.Request();
request.query('select * from users')
.then(result =>{
res.json(result.recordset);
});
// Hard coding for simplicity. Pretend this hits a real database
// res.json([
// {"id": 1,"firstName":"Bob","lastName":"Smith","email":"[email protected]"},
// {"id": 2,"firstName":"Tammy","lastName":"Norton","email":"[email protected]"},
// {"id": 3,"firstName":"Tina","lastName":"Lee","email":"[email protected]"}
// ]);
});
app.listen(app.get('port'), function() {
console.log("Node app is running at localhost:" + app.get('port'));
});