In this tutorial we install PostgreSQL, and an object relational mapper (ORM) called Sequelize for NodeJS.
If you can’t get a database connection after below, and things are silently failing, try updating the ‘pg’ package to the latest version. This is a common issue where things silently fail and it comes to mind last.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install postgresql
brew services start postgresql
psql postgres
CREATE ROLE “express-mvp-dbuser” WITH LOGIN PASSWORD ‘123.456’
CREATE DATABASE “express-mvp-db”;
DROP DATABASE “express-mvp-db”;
DROP ROLE “express-mvp-dbuser”;
npm install sequelize --save
npm install pg --save
npm install sequelize-cli -g
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')
}
sequelize init
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"
}
}