add postgres and environemt file

This commit is contained in:
Paul Trowbridge 2019-01-31 16:32:34 -05:00
parent c570ea1917
commit d791dd3882
3 changed files with 36 additions and 2 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
npm-debug.log npm-debug.log
*.swp *.swp
/node_modules /node_modules
.env

View File

@ -1,7 +1,39 @@
require('dotenv').config();
const express = require('express'); const express = require('express');
const server = 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')) server.listen(3000,() => console.log('started'))

View File

@ -9,6 +9,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"dotenv": "^6.2.0",
"express": "^4.16.4", "express": "^4.16.4",
"pg": "^7.8.0" "pg": "^7.8.0"
} }