序列化 config.json / config.js

eth*_*it3 5 node.js sequelize.js

我使用express 和sequelize 来创建Web 服务器。我使用sequelize的CLI来创建模型和迁移。

我想更改config.jsonconfig.js以便能够使用环境变量。

我按照文档创建了 `.sequelizerc' 文件,如下 =>

const path = require('path');

module.exports = {
  'config': path.resolve('config', 'config.js'),
  'models-path': path.resolve('models'),
  'seeders-path': path.resolve('seeders'),
  'migrations-path': path.resolve('migrations')
}
Run Code Online (Sandbox Code Playgroud)

这对于 CLI 续集来说是有效的,我可以创建模型或开始迁移,但我无法启动服务器,因为它会查找文件config.json

所以我的问题是如何确保服务器启动时能够读取config.js.

当我跑步时node bin/www我收到

Error: Cannot find module '/nodeTest/nodejs-relationships/models/../config/config.json'
Run Code Online (Sandbox Code Playgroud)

eth*_*it3 4

问题实际上是我的index.js文件位于/models目录中,实际上,它config.json默认尝试要求,只需将其替换.json.js