I need to run third party application in node.js environment but Sequelize throws 'Dialect needs to be explicitly supplied as of v4.0.0' I've found similar topic here Dialect needs to be explicitly supplied as of v4.0.0 but 'export NODE_ENV=development' doesn't work and I can not find Sequelize config file. How can I fix this error?
Here is code:
const Sequelize = require('sequelize');
const scheme = require('./scheme');
const Op = Sequelize.Op;
const sequelize = new Sequelize(null, null, {
dialect: 'sqlite',
storage: 'db.sqlite3',
operatorsAliases: { $and: Op.and },
logging: false
});
scheme(sequelize);
sequelize.sync();
module.exports.sequelize = sequelize;
module.exports.models = sequelize.models;
Sequelize is independent from specific dialects. This means that you'll have to install the respective connector library to your project yourself.
Sequelize is a promise-based ORM for Node. js. It works with PostgreSQL, MySQL, SQLite and MSSQL dialects and features solid transaction support, relations, read replication and more. Object Relational Mapping (ORM) is a technique of accessing a relational database from an object-oriented language.
You simply supply the dialect when you initialize sequelize;
const sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect: // pick one of 'mysql','sqlite','postgres','mssql',
});
Node cannot find your environment to load in the config file.
You can easily fix by running this
export NODE_ENV=development; npx sequelize db:migrate
This should export to NODE_ENV the environment needed to run it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With