add postgres and environemt file
This commit is contained in:
parent
c570ea1917
commit
d791dd3882
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
npm-debug.log
|
||||
*.swp
|
||||
/node_modules
|
||||
.env
|
34
index.js
34
index.js
@ -1,7 +1,39 @@
|
||||
require('dotenv').config();
|
||||
const express = require('express');
|
||||
const server = express();
|
||||
const pg = require('pg');
|
||||
|
||||
var Postgres = new pg.Client({
|
||||
user: process.env.user,
|
||||
password: process.env.password,
|
||||
host: process.env.host,
|
||||
port: process.env.port,
|
||||
database: process.env.database,
|
||||
ssl: false,
|
||||
application_name: "osm_api"
|
||||
});
|
||||
Postgres.connect();
|
||||
|
||||
Postgres.FirstRow = function(inSQL,args, inResponse)
|
||||
{
|
||||
Postgres.query(inSQL,args, (err, res) => {
|
||||
if (err === null)
|
||||
{
|
||||
inResponse.json(res.rows[0]);
|
||||
return;
|
||||
}
|
||||
inResponse.json(err.stack);
|
||||
});
|
||||
};
|
||||
|
||||
server.get('/list_sources', function (req,res) {
|
||||
var sql = "select jsonb_agg(defn) from tps.srce";
|
||||
console.log(req.query);
|
||||
Postgres.FirstRow(sql,[],res);
|
||||
})
|
||||
|
||||
server.get('/', (req,res) => res.send('its running yay 🎡'))
|
||||
|
||||
server.get('/', (req,res) => res.send('🎡'))
|
||||
server.listen(3000,() => console.log('started'))
|
||||
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dotenv": "^6.2.0",
|
||||
"express": "^4.16.4",
|
||||
"pg": "^7.8.0"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user