bocajbee

index.js

Mar 30th, 2021
819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require('dotenv').config()
  2. const express = require("express");
  3. const app = express();
  4. const {Pool} = require('pg');
  5.  
  6. // https://www.npmjs.com/package/dotenv
  7. // https://www.npmjs.com/package/@googlemaps/google-maps-services-js
  8. const {Client} = require("@googlemaps/google-maps-services-js");
  9.  
  10. // https://node-postgres.com/features/connecting
  11. const db = new Pool({
  12.   user: "postgres",
  13.   host: "127.0.0.1",
  14.   database: 'park_locator',
  15.   password: "postgres",
  16.   port: 5432
  17. });
  18.  
  19. // connect my node to pg db
  20. db.connect();
  21.  
  22. // instantiate the client to make a call to one of the APIs.
  23. const client = new Client({});
  24.  
  25. client
  26.   .elevation({
  27.     params: {
  28.       locations: [{ lat: 45, lng: -110 }],
  29.       key: process.env.KEY,
  30.     },
  31.     timeout: 1000, // milliseconds
  32.   })
  33.   .then((r) => {
  34.     console.log(r.data.results[0].elevation);
  35.   })
  36.   .catch((e) => {
  37.     console.log(e.response.data.error_message);
  38.   });
  39.  
  40. // middleware. express.json() allows us to parse json from the client to our back end
  41. app.use(express.json());
  42.  
  43. // app listener
  44. app.listen(5000, () => {
  45.   console.log("Server has started on port 5000")
  46. });
Advertisement
Add Comment
Please, Sign In to add comment