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

Question

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?

Answer

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.

This answer was originally posted on Stack Overflow. You can find the full discussion here

Related Posts

Transfer git repositories from GitLab to GitHub - can we, how to and pitfalls (if any)?

## Question Can one transfer repositories from GitLab to GitHub if the need be. If so, how exactly can I go about doing the same? Also, are there any pitfalls in doing so or precautionary measures

Read More

Cannot set headers after they are sent to the client - error

## Question Error `[ERR_HTTP_HEADERS_SENT]`: Cannot set headers after they are sent to the client ```text `at ServerResponse.setHeader (_http_outgoing.js:558:11) at ServerResponse.header (D:\D

Read More

Pulling data with 'Where' and 'Include' statements at the same time

## Question I have managed to get my include statements working with my foreign keys however when I try to add a 'where' statement to the findAll statement I am getting the below error. I have check

Read More