This commit is contained in:
Muhammad Azeez 2021-01-12 13:06:29 +03:00
parent 354c8260a1
commit f78d6b3d73
4 changed files with 1242 additions and 0 deletions

32
Node/Property/index.js Normal file
View File

@ -0,0 +1,32 @@
const express = require('express')
const bodyParser = require('body-parser')
const db = require('./queries')
const app = express()
const port = 3000
const getRealEstates = (request, response) => {
pool.query('SELECT * FROM real_estae ORDER BY id ASC', (error, results) => {
if (error) {
throw error
}
response.status(200).json(results.rows)
})
}
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: true,
})
);
app.get('/', (request, response) => {
response.json({ info: 'Node.js, Express, and Postgres API' })
});
app.get('/real-estate', db.getAllRealEstate);
app.listen(port, () => {
console.log(`App running on port ${port}.`)
});

1174
Node/Property/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,15 @@
{
"name": "real-estate",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"pg": "^8.5.1"
}
}

21
Node/Property/queries.js Normal file
View File

@ -0,0 +1,21 @@
const Pool = require('pg').Pool
const pool = new Pool({
user: 'postgres',
host: 'localhost',
database: 'real_estate',
password: 'root',
port: 5432,
});
const getAllRealEstate = (request, response) => {
pool.query('SELECT * FROM real_estate ORDER BY id ASC', (error, results) => {
if (error) {
throw error
}
response.status(200).json(results.rows)
})
};
module.exports = {
getAllRealEstate
}