Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var db_config = {
- user: 'marta', // name of the user account
- password : 'ahX0jai3',
- database: 'martadb', // name of the database
- max: 10, // max number of clients in the pool
- idleTimeoutMillis: 30000 // how long a client is allowed to remain idle before being closed
- }
- // call the packages we need
- var express = require('express'); // call express
- var bodyParser = require('body-parser');
- var pg = require('pg');
- var format = require('pg-format');
- var app = express();
- const client = new pg.Client(db_config);
- client.connect();
- app.use(bodyParser.urlencoded({ extended: true }));
- app.use(bodyParser.json());
- var port = process.env.PORT || 8080; // set our port
- var router = express.Router(); // get an instance of the express Router
- router.get('/preco/cidade/:id_cidade/quartos/:nquartos', async (req, res) => {
- var query_preco = format('SELECT AVG(valor_venda) FROM anuncios WHERE num_quartos = %L and id_cidade = %L',req.params.nquartos, req.params.id_cidade);
- const {rows} = await client.query(query_preco);
- console.log(rows);
- res.json(rows[0]);
- });
- app.use('/marta', router);
- app.listen(port);
- console.log('Magic happens on port ' + port);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement