-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (35 loc) · 991 Bytes
/
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
//express
const express = require('express')
var cors = require('cors')
const {oracledb} = require("./db-config");
const path = require("path");
require("dotenv").config({ path: path.resolve(__dirname, ".env") });
const app = express()
const port = 5000
//app.use(cors())
app.use(cors())
//routes
app.get("/", async function (req, res) {
let connection = await oracledb.getConnection({
user: process.env.USERNAME,
password: process.env.PASSWORD,
connectionString: process.env.CONNECTIONSTRING,
});
try {
const sql = `SELECT * FROM ACTIVEUSER`;
const result = await connection.execute(sql);
res.status(200).send(result.rows);
} catch (err) {
console.error(err);
res.status(502).send(err);
}
try {
await connection.close();
} catch (err) {
console.error(err);
res.status(502).send(err);
}
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})