Install Postgres and Sequelize

    Learn to install an SQL database on your Mac OS X

    Bahadir Balban

    Started Tech Buzz

    @learningexpressjs

    In this tutorial we install PostgreSQL, and an object relational mapper (ORM) called Sequelize for NodeJS.

    Install Homebrew

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

    Install PostgreSQL

    brew install postgresql

    Start PostgreSQL

    brew services start postgresql

    Start PostgreSQL shell

    psql postgres

    Create User in PostgreSQL

    CREATE ROLE “express-mvp-dbuser” WITH LOGIN PASSWORD ‘123.456’

    Create Database

    CREATE DATABASE “express-mvp-db”;

    Delete Database

    DROP DATABASE “express-mvp-db”;

    Delete User

    DROP ROLE “express-mvp-dbuser”;

    Install Sequelize and deps

    npm install sequelize --save
    npm install pg --save
    npm install sequelize-cli -g

    Snippet for .sequelizerc

    const path = require('path');
    module.exports = {
      'config': path.resolve('config', 'config.js'),
      'models-path': path.resolve('', 'models'),
      'seeders-path': path.resolve('', 'seeders'),
      'migrations-path': path.resolve('', 'migrations')
    }

    Initialize Sequelize environment

    sequelize init

    Snippet for config/config.js

    module.exports = {
      "development": {
        "username": "express-mvp-dbuser",
        "password": '123.456',
        "database": "express-mvp-db",
        "host": "127.0.0.1",
        "dialect": "postgres",
        "port" : 5432
      },
      "test": {
        "username": "root",
        "password": null,
        "database": "database_test",
        "host": "127.0.0.1",
        "dialect": "mysql"
      },
      "production": {
        "username": "root",
        "password": null,
        "database": "database_production",
        "host": "127.0.0.1",
        "dialect": "mysql"
      }
    }


    Did you like this episode?

    Buzz it and share it with your friends

    Buzz2

    You Might Also Like...


    Join The Discussion