Self-contained Express-Postgresql-React project container.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
astronomy/server/app.js

26 lines
584 B

const express = require('express')
const app = express()
const port = 3005
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))
const Pool = require('pg').Pool
const pool =
new Pool({
user: 'postgres',
password: '',
host: 'postgres',
database: 'astronomy',
port: 5432,
})
const getUsers = (request, response) => {
pool.query('SELECT * FROM users', (error, results) => {
if (error) {
response.status(500).json(error.message)
} else {
response.status(200).json(results.rows)
}
})
}
app.get('/', getUsers)