mirror of
https://github.com/SrIzan10/starters.git
synced 2026-05-01 11:05:16 +00:00
24 lines
681 B
TypeScript
24 lines
681 B
TypeScript
import bodyParser from "body-parser";
|
|
import express from "express";
|
|
import pg from "pg";
|
|
|
|
// Connect to the database using the DATABASE_URL environment
|
|
// variable injected by Railway
|
|
const pool = new pg.Pool();
|
|
|
|
const app = express();
|
|
const port = process.env.PORT || 3333;
|
|
|
|
app.use(bodyParser.json());
|
|
app.use(bodyParser.raw({ type: "application/vnd.custom-type" }));
|
|
app.use(bodyParser.text({ type: "text/html" }));
|
|
|
|
app.get("/", async (req, res) => {
|
|
const { rows } = await pool.query("SELECT NOW()");
|
|
res.send(`Hello, World! The time from the DB is ${rows[0].now}`);
|
|
});
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Example app listening at http://localhost:${port}`);
|
|
});
|