mirror of
https://github.com/ditkrg/AuthorizationServerDemos.git
synced 2026-01-23 01:46:39 +00:00
node api
This commit is contained in:
parent
354c8260a1
commit
f78d6b3d73
32
Node/Property/index.js
Normal file
32
Node/Property/index.js
Normal 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
1174
Node/Property/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
15
Node/Property/package.json
Normal file
15
Node/Property/package.json
Normal 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
21
Node/Property/queries.js
Normal 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
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user