Skip to content

Commit 5c9f018

Browse files
committed
first commit
0 parents  commit 5c9f018

File tree

5 files changed

+1120
-0
lines changed

5 files changed

+1120
-0
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.git
2+
node_modules
3+
.env

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.DS_Store
3+
.env

index.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import Fastify from 'fastify';
2+
import pg from 'pg';
3+
4+
const PORT = process.env.PORT || 3000;
5+
6+
const fastify = Fastify({
7+
logger: true
8+
});
9+
10+
fastify.get('/', function (request, reply) {
11+
reply.send('hello world');
12+
});
13+
14+
async function initDb () {
15+
const {Pool} = pg;
16+
const pool = new Pool();
17+
18+
pool.on('connect', function () {
19+
console.log('PG CONNECTED');
20+
});
21+
22+
pool.on('acquire', function () {
23+
console.log('PG ACQUIRE');
24+
});
25+
26+
pool.on('remove', function () {
27+
console.log('PG REMOVE');
28+
});
29+
30+
pool.on('error', function (error) {
31+
console.log('PG ERROR');
32+
console.log(error);
33+
fastify.log.error(error);
34+
});
35+
36+
await pool.connect();
37+
38+
// Test query
39+
const result = await pool.query('select version();');
40+
console.log(result.rows[0]);
41+
}
42+
43+
async function start () {
44+
try {
45+
await initDb();
46+
await fastify.listen(PORT);
47+
} catch (error) {
48+
fastify.log.error(error);
49+
process.exit(1);
50+
}
51+
}
52+
53+
start();

0 commit comments

Comments
 (0)