Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON the right format for config? #77

Closed
anthonator opened this Issue Dec 27, 2014 · 9 comments

Comments

7 participants
@anthonator
Copy link

anthonator commented Dec 27, 2014

Is JSON the right format for the config? The only reason I ask is because I generally pull production config from ENV. You fine people have done a good job making this thing customizable so I wouldn't be surprised if you have something for this and I'm not seeing it.

@sdepold

This comment has been minimized.

Copy link
Member

sdepold commented Dec 29, 2014

Hi @anthonator,

there is this thing called use_env_variable... You can find it here:

if (key === "use_env_variable") {

If I get that right, and please let me know if that is the truth, because we should add that to the docs then, you can do this in your config.json:

{
  "production": {
    "use_env_variable": "DB_HOST"
  }
}

Having that you can set an env var DB_HOST to the URL of your database. Not entirely sure how that url looks like though. Please let me know if this helps already. Otherwise I will try to find out one is supposed to use that :D

@anthonator

This comment has been minimized.

Copy link
Author

anthonator commented Dec 30, 2014

Thanks for the reply @sdepold! I haven't had a chance to try your suggestion yet, but it seems like a rather round about solution when you can write native JavaScript to handle this scenario easily.

module.exports = {
  production: {
    database: process.env.PG_DATABASE,
    host: process.env.PG_HOST,
    dialect: 'postgres'
    ...snip...
  }
};

Is there any reason the above wouldn't work? Could simplify the config code (no JSON parsing!).

@sdepold

This comment has been minimized.

Copy link
Member

sdepold commented Dec 30, 2014

Yeah that would work as well, you only have to tell the CLI to use the js file as configuration file:

sequelize -c my_config.js
@anthonator

This comment has been minimized.

Copy link
Author

anthonator commented Dec 30, 2014

Perfect! Thanks @sdepold! This might be handy in the docs if it's not already there.

@leehankyeol

This comment has been minimized.

Copy link

leehankyeol commented Oct 7, 2016

For anyone who might be lost like me...

If you're using dotenv, you should require it in config.js.

const dotenv = require('dotenv').config();

module.exports = {
  development: {
    database: process.env.DB_NAME,
    username: process.env.DB_USERNAME,
    password: process.env.DB_PASSWORD,
    host: process.env.DB_HOST,
    port: process.env.DB_PORT,
    dialect: 'mysql',
    define: {
      underscored: true
    },
  },
}
@mcranston18

This comment has been minimized.

Copy link

mcranston18 commented Jun 14, 2017

For anyone wondering why sequelize -c my_config.js doesn't work, the syntax has been updated. Use this instead sequelize --config my_config.js

@frederikhors

This comment has been minimized.

Copy link

frederikhors commented Aug 26, 2018

Is this still a problem or am I wrong? #688

@noodlebreak

This comment has been minimized.

Copy link

noodlebreak commented Jan 22, 2019

There is no config.js in my installation. Is this to be manually written? I have an automatically created models/index.js when I ran sequelie init.

@Nastromo

This comment has been minimized.

Copy link

Nastromo commented Feb 4, 2019

Current version of sequelize-cli supports config.JS by default. All you have to do is write your config.js as this:

require('dotenv').config();

module.exports = {
    dev: {
        username: process.env.DB_USER,
        password: process.env.DB_PASS,
        database: process.env.DB_NAME,
        host: process.env.DB_HOST,
        dialect: 'mysql'
    },
    "production": {
        "username": process.env.DB_USER,
        "password": process.env.DB_PASS,
        "database": process.env.DB_NAME,
        "host": process.env.DB_HOST,
        "dialect": "mysql"
    }
}

Note - your "dev" parameter name in config.js has to be exactly the same as in your .env file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.