Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Since It's not a good idea to have everything on the server.js I moved the pool creation to this file
- // Require the pg module
- const { Pool } = require('pg');
- // You can either do this or check if we are in production like in server.js
- // In this case if the DATABASE_URL is declared we use it to the connection
- const { DATABASE_URL } = process.env;
- if (DATABASE_URL){
- console.log("Using database url");
- var pool = new Pool({
- connectionString: DATABASE_URL
- });
- }else{
- // if the database url is not set use a local database for dev.
- console.log("Using database info");
- var pool = new Pool({
- user: '<USER>',
- host: 'localhost',
- database: '<DATABASE_NAME>',
- password: '<DATABASE_PASSWORD>',
- port: 5432 // default port for postgres
- });
- }
- module.exports = pool;
- // To use this pool on another file, use something like this:
- // const pool = require('path/to/file/database');
Add Comment
Please, Sign In to add comment