Coder Social home page Coder Social logo

Comments (9)

leehankyeol avatar leehankyeol commented on August 17, 2024 79

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
    },
  },
}

from cli.

mcranston18 avatar mcranston18 commented on August 17, 2024 27

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

from cli.

sdepold avatar sdepold commented on August 17, 2024 12

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

from cli.

sdepold avatar sdepold commented on August 17, 2024 6

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

from cli.

Nastromo avatar Nastromo commented on August 17, 2024 3

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

from cli.

anthonator avatar anthonator commented on August 17, 2024

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!).

from cli.

anthonator avatar anthonator commented on August 17, 2024

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

from cli.

frederikhors avatar frederikhors commented on August 17, 2024

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

from cli.

noodlebreak avatar noodlebreak commented on August 17, 2024

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.

from cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.