-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (24 loc) · 696 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
const express = require('express');
const Postgres = require('postgres');
const morgan = require('morgan');
const app = express();
const {
pool
} = require('./dbConnection');
app.set("view engine", "ejs");
app.use(morgan("dev"));
app.get("/", async (req, res) => {
return res.render("index");
});
app.post("/", async (req, res) => {
const searchKey = "%" + req.query.key + "%";
const {
rows
} = await pool.query("SELECT name FROM testingTable WHERE name LIKE $1 LIMIT 15;", [searchKey]);
console.log('rows :>> ', rows);
return res.json({
searchKey,
results: rows
})
});
app.listen(3000, () => console.log("server listening on 3000"));