-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
51 lines (42 loc) · 1.61 KB
/
server.js
File metadata and controls
51 lines (42 loc) · 1.61 KB
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
/*eslint-env node*/
//---------------------------------------------------------------------------------------
// nodejs. starter application for Bluemix
//---------------------------------------------------------------------------------------
// This application uses express as its web server
// for more info, see http://expressjs.com
var express = require('express');
// cfenv provides access to your Cloud Foundry environment
// for more info, see: https://www.npmjs.com/package/cfenv
var cfenv = require('cfenv');
// create a new express server
var app = express();
// get the app environment from Cloud foundry
var appEnv = cfenv.getAppEnv();
// Include the ibm_db module
var ibmdb = require('ibm_db');
global.dbConnString = "DATABASE=YOUR_DATABASE_NAME;"
+ "HOSTNAME=YOUR_HOSTNAME;PORT=50000;PROTOCOL=TCPIP;"
+ "UID=USERNAME;PWD=PASSWORD";
// start server on the specified port and binding host
app.listen(appEnv.port, function() {
// print a message when the server starts listening
console.log("server starting on " + appEnv.url);
ibmdb.open(dbConnString, function(err, conn) {
if (err) {
console.log("Error", err);
} else {
var query = "SELECT * FROM TEST";
conn.query(query, function(err, rows) {
if (err) {
console.log("Error", err);
return;
} else {
console.log(rows);
conn.close(function() {
console.log("Connection closed successfully");
});
}
});
}
})
});