Guest User

Untitled

a guest
Jun 27th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. // Since It's not a good idea to have everything on the server.js I moved the pool creation to this file
  2.  
  3. // Require the pg module
  4. const { Pool } = require('pg');
  5.  
  6. // You can either do this or check if we are in production like in server.js
  7. // In this case if the DATABASE_URL is declared we use it to the connection
  8. const { DATABASE_URL } = process.env;
  9. if (DATABASE_URL){
  10. console.log("Using database url");
  11. var pool = new Pool({
  12. connectionString: DATABASE_URL
  13. });
  14. }else{
  15. // if the database url is not set use a local database for dev.
  16. console.log("Using database info");
  17. var pool = new Pool({
  18. user: '<USER>',
  19. host: 'localhost',
  20. database: '<DATABASE_NAME>',
  21. password: '<DATABASE_PASSWORD>',
  22. port: 5432 // default port for postgres
  23. });
  24. }
  25.  
  26. module.exports = pool;
  27.  
  28. // To use this pool on another file, use something like this:
  29. // const pool = require('path/to/file/database');
Add Comment
Please, Sign In to add comment