Skip to content

Instantly share code, notes, and snippets.

@tanay-pingalkar
Last active April 30, 2021 07:31
Show Gist options
  • Save tanay-pingalkar/d7f51ca0237d3e2fcc93e4f3085d343a to your computer and use it in GitHub Desktop.
Save tanay-pingalkar/d7f51ca0237d3e2fcc93e4f3085d343a to your computer and use it in GitHub Desktop.
const express = require("express");
const app = express();
const Pool = require("pg").Pool;
const pool = new Pool({
user: "postgres",
database: "example",
password: "postgres",
host: "db",
port:5555
});
pool.query(`CREATE TABLE users (
ID SERIAL PRIMARY KEY,
name VARCHAR(30),
email VARCHAR(30)
)`);
app.get("/", async (req, res) => {
await pool.query("INSERT INTO users (name, email) VALUES ('docker','this is cool')");
const data = await pool.query("SELECT * FROM users;");
res.send(data.rows);
});
app.listen(port, function () {
console.log("Example app listening on port 8080! 🚀");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment