Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
890 B
1
Indexable
Never
const http = require('http');
const { Pool } = require('pg');
require('dotenv').config();

let hostname = 'localhost';
let port = 8000;

let server = http.createServer((request, response) => {
  response.statusCode = 200;
  response.setHeader('Content-Type', 'text/plain');
  response.end('');
});

let connectDb = async () => {
  try {
    const POOL = new Pool({
      user: process.env.PGUSER,
      host: process.env.PGHOST,
      database: process.env.PGDATABASE,
      password: process.env.PGPASSWORD,
      port: process.env.PGPORT,
    });

    await POOL.connect();
    let response = await POOL.query('SELECT * FROM context');
    console.log(response);

    await POOL.end();

    module.exports = POOL;
  } catch (error) {
      console.log(error);
  }
}

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
  connectDb();
});