Answers for "sequelize connect to postgres database"

0

sequelize connect to postgres database

const { Sequelize } = require('sequelize'); // <- npm install sequelize pg

// CONNECTION CONFIGURATION
config = {
    host    : "localhost",  
    port    : "5432",       
    dialect: 'postgres'

}
const DB_USER = "postgres";
const DB_NAME = "postgres";
const DB_PASS = "password";

// 1) Using a configuration object:
const sequelize = new Sequelize( DB_NAME, DB_USER, DB_PASS, config );

// 2) Passing a connection URI
// const sequelize = new Sequelize(`postgres://${DB_USER}:${DB_PASS}@${config.host}:${config.port}/${DB_NAME}`); 

// CLOSE THE CONNECTION
sequelize.close().then(() =>{
    console.log("Connection closed.");
});
Posted by: Guest on October-21-2021

Code answers related to "sequelize connect to postgres database"

Code answers related to "Javascript"

Browse Popular Code Answers by Language