Skip to content

Commit 19237fa

Browse files
author
Dan McGhan
committed
Added sample code for javascript/rest-api part 1
1 parent b1c902e commit 19237fa

File tree

7 files changed

+518
-0
lines changed

7 files changed

+518
-0
lines changed

javascript/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ This directory contains Oracle Database JavaScript examples for:
44

55
- JavaScript on the JVM using the Nashorn engine (Hotspot JDk or JRE, other Java SE 8 compliant VMs, OJVM).
66
- node-oracledb for Node.js, allowing you to write mid-tier and networking applications in JavaScript.
7+
- Creating a REST API with Node.js and Oracle Database.

javascript/rest-api/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Creating a REST API with Node.js and Oracle Database
2+
3+
This folder contains sample code from the [Creating a REST API with Node.js and Oracle Database](https://jsao.io/2018/03/creating-a-rest-api-with-node-js-and-oracle-database/) blog series. See that post for more details.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
port: process.env.HTTP_PORT || 3000
3+
};
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const webServer = require('./services/web-server.js');
2+
3+
async function startup() {
4+
console.log('Starting application');
5+
6+
try {
7+
console.log('Starting web server');
8+
9+
await webServer.start();
10+
} catch (err) {
11+
console.error(err);
12+
13+
process.exit(1); // Non-zero failure code
14+
}
15+
}
16+
17+
startup();
18+
19+
async function shutdown(e) {
20+
let err = e;
21+
22+
console.log('Shutting down');
23+
24+
try {
25+
console.log('Closing web server');
26+
27+
await webServer.stop();
28+
} catch (e) {
29+
console.log('Encountered error', e);
30+
31+
err = err || e;
32+
}
33+
34+
console.log('Exiting process');
35+
36+
if (err) {
37+
process.exit(1);
38+
} else {
39+
process.exit(0);
40+
}
41+
}
42+
43+
process.on('SIGTERM', () => {
44+
console.log('Received SIGTERM');
45+
46+
shutdown();
47+
});
48+
49+
process.on('SIGINT', () => {
50+
console.log('Received SIGINT');
51+
52+
shutdown();
53+
});
54+
55+
process.on('uncaughtException', err => {
56+
console.log('Uncaught exception', err);
57+
58+
shutdown(err);
59+
});

0 commit comments

Comments
 (0)