Last active
April 30, 2021 07:31
-
-
Save tanay-pingalkar/d7f51ca0237d3e2fcc93e4f3085d343a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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