Skip to content

Commit ae5adac

Browse files
authored
Adding example nodejs with oracledb application
1 parent 6ebb570 commit ae5adac

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

example/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM katturaja/docker-node-oracle-base:8.12.0-slim
2+
3+
# Create app base directory
4+
RUN mkdir -p /src
5+
6+
# Specify the "working directory" for the rest of the Dockerfile
7+
WORKDIR /src
8+
9+
COPY . /src
10+
11+
# clean
12+
RUN npm cache clean -f \
13+
&& npm install --only=prod
14+
15+
EXPOSE 3000
16+
CMD ["node", "server.js"]

example/index.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
var oracledb = require('oracledb');
2+
var Hapi = require("hapi");
3+
var Joi = require("joi");
4+
5+
oracledb.getConnection(
6+
{
7+
user : "<Username>",
8+
password : "<Password>",
9+
connectString : "<Oracle DB Connection String>"
10+
},
11+
function(err, connection) {
12+
if (err) {
13+
console.error(err.message);
14+
return;
15+
}
16+
console.log("Oracle DB Connection Established successfully");
17+
doRelease(connection);
18+
});
19+
20+
function doRelease(connection) {
21+
connection.close(
22+
function(err) {
23+
if (err)
24+
console.error(err.message);
25+
});
26+
}
27+
28+
const server = new Hapi.Server();
29+
30+
server.connection({"port": 3000 });
31+
32+
server.route({
33+
method: "GET",
34+
path: "/",
35+
handler: (request, response) => {
36+
response("Hello World");
37+
}
38+
});
39+
40+
41+
server.start(error => {
42+
if(error) {
43+
throw error;
44+
}
45+
console.log("Listening at " + server.info.uri);
46+
});

example/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "demoapp",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"hapi": "^16.6.3",
13+
"joi": "^14.0.0",
14+
"oracledb": "2.3.0"
15+
}
16+
}

0 commit comments

Comments
 (0)