Search code examples
angularjspostgresqlangular-fullstack

Connecting PostgreSQL DB to Web App Generated with Angular-fullstack


I am having immense troubles connecting my postgres db to my web app. I have created my web app using yeoman alongside the angular-fullstack generator.I am completely new to this process, and I cannot find any solid information. Here is my index.js for sqldb (located within server/config)

/*** Sequelize initialization module */ 
 'use strict';
 import path from 'path';
 import config from '../config/environment';
 import Sequelize from 'sequelize';
 var db = {
 Sequelize,
 sequelize: new Sequelize(5432,"postgres","postgres","password")
 };
 // Insert models below
 db.Thing = db.sequelize.import('../api/thing/thing.model');
 db.User = db.sequelize.import('../api/user/user.model');
 module.exports = db;

I put the port, database name, user credentials in as you can see. I do not know if that is proper. I have not installed any postgres drivers in, or initiated them, etc.. My goal is to connect my two api, thing and user, to the database with corresponding tables, thing and user. I hope my question is not too general, and I recognize this may be a very simply issue but, I want to know how to fully complete a web app with a database.


Solution

  • I would use a config.json in /app/server/config that would outline your db info. For example:

    { 
    \\ stage = your product stage
    "stage": {
    "username": "db.usrnm",
    "password": "db.pswd",
    "database": "db",
    "host": "127.0.0.1",
    "dialect": "postgres",
    "port": "5432"
     }
     }
    

    As for adding a driver, I think that is already covered if you are using a generator -- I may be wrong.