Home > Blockchain >  Sequelize ORM, is this normal that we have to put database info into a json file?
Sequelize ORM, is this normal that we have to put database info into a json file?

Time:12-10

I am trying to go deeper with Sequelize and especially using migration. But, I can't imagine that the documentation requires that we use a json file to put database info. So, my question is, "how can this be possible when I am using Git and GiHub for my project?" If I decide to ignore the file, how can my colleagues get to know about the exact structure I am using? Or am I missing something? Should you share your exact workflow for Sequelize, Postgress and Git?

CodePudding user response:

Yes, it is normal to put your database info in either a json or js file, for better and improved security you should pull your database configurations from a .env file or from ENV Variables on your server. i.e instead of:

development: {
    username: 'database_dev',
    password: 'database_dev',
    database: 'database_dev',
    host: '127.0.0.1',
    port: 3306,
    dialect: 'mysql'
  }

You should have something like this in your config file:

development: {
    username: process.env.DB_USERNAME,
    password: process.env.DB_PASSWORD,
    database: process.env.DB_NAME,
    host: process.env.DB_HOSTNAME,
    port: process.env.DB_PORT,
    dialect: process.env.DIALECT
}

Notice that your username and password now come from process.env.

You will then have to create a .env file that will contain all sensitive information like passwords and this file you will have to add to .gitignore and never commit it to git. Read more about env files here.

When sharing your code to github, you include your config.json/config.js file but your colleagues or potential hackers won't know the username, password or any database configurations and this is done on purpose to avoid having sensitive information like passwords in your code.

The database configuration will then have to be shared with them separately or can only exist on one of your servers as ENV Variables.

CodePudding user response:

I finally find what I was looking for, so I don't know any other way to share it if not with this answer box.

I got inspiration from this answer

  1. install babel-register as dev dependency
  2. require it in .sequelizerc
  3. make sure the config file is in a cjs format. It's a commonJS file ext.
  • Related