25 lines
535 B
JavaScript
25 lines
535 B
JavaScript
const express = require("express");
|
|
const { Pool } = require("pg");
|
|
|
|
const app = express();
|
|
|
|
const pool = new Pool({
|
|
host: "postgres-service",
|
|
user: "postgres",
|
|
password: "postgres",
|
|
database: "testdb",
|
|
port: 5432,
|
|
});
|
|
|
|
app.get("/", async (req, res) => {
|
|
try {
|
|
const result = await pool.query("SELECT NOW()");
|
|
res.send("DB Time: " + result.rows[0].now);
|
|
} catch (err) {
|
|
res.send("Database not ready");
|
|
}
|
|
});
|
|
|
|
app.listen(3000, () => {
|
|
console.log("Server running on port 3000");
|
|
}); |