-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
96 lines (73 loc) · 2.72 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* Created by abhilashak on 10/14/18.
*/
// set up ========================
var express = require('express');
var app = express(); //create our app w/ express
var http = require('http');
var https = require('https');
var oracledb = require('oracledb');
var hostname = '<your oracle db connection hostname>';
console.log('Hostname is : '+hostname);
connstr =
"(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = 1521)) (CONNECT_DATA =(SERVER = DEDICATED)(SID = orcl)))";
console.log('Starting to get oracle connection . . . . .. ');
oracledb.getConnection(
{
user : '<username>',
password : '<password>',
connectString : connstr
//connectString : "(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA =(SID= ORCL)))"
},
function(err, connection) {
console.log('Starting to establish a connection. . . . . ');
if (err) {
console.error(err.message);
return;
}
console.log('Connection was successful!');
connection.close(
function(err) {
if (err) {
console.error(err.message);
return;
}
});
});
app.get('/api/customapp/loadinitialdata',function(req,res){
console.log("inside loadinitialdata");
var rslt = new Object();
oracledb.getConnection(
{
user : "<username>",
password : "<password>",
connectString : connstr
},
function(err, connection)
{
if (err) { console.error(err.message);
res.render('index', {result: 'Oracle error!'}); return; }
connection.execute(
"select * from prodcoffee" ,
//Above is a sample query that returns some result
function(err, result)
{
if (err) {
console.error(err.message);
return;
}
rslt = JSON.stringify(result);
res.json(JSON.parse(rslt));
connection.release(
function(err) {
console.log('Releasing connection');
if (err) { console.error(err.message); }
});
});
});
});
var distDir = '<You local project location>'; //something like '/Users/AK/MyAngularProjects/CustomApp'
app.use(express.static(distDir));
// listen (start app with node server.js) ======================================
app.listen(8081);
console.log("App listening on port 8081");