diff --git a/.gitignore b/.gitignore index 4d2dcdf..2b7af74 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ npm-debug.log *.swp -/node_modules \ No newline at end of file +/node_modules +.env \ No newline at end of file diff --git a/index.js b/index.js index ca687ef..6dece35 100644 --- a/index.js +++ b/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')) diff --git a/package.json b/package.json index 951a50b..454d9a7 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "author": "", "license": "ISC", "dependencies": { + "dotenv": "^6.2.0", "express": "^4.16.4", "pg": "^7.8.0" }