node.js - 导出模块值

标签 node.js typescript sails.js waterline

我很困惑。我有以下 JavaScript 文件:

module.exports = {
  connection: 'freshairMysqlServer',
  tableName: 'Accounts',
  autoCreatedAt: false,
  autoUpdatedAt: false,
  autoPK: false,

  attributes: {
    idAccounts: {
      type: 'integer',
      primaryKey: true
    },
    AccountName: {
      type: 'string'
    },
    idOrganization: {
      type: 'integer'
    }
  },

  GetAccounts: function (page, cb) {
    Accounts.query('SELECT Accounts.AccountName as AccountName,' +
      ' Organizations.Name as Organization FROM Accounts' +
      ' JOIN Organizations on Accounts.idOrganization = Organizations.idOrganizations',
      function (err, results) {
        if (err) cb(err)
        else cb(null, results);
      });
  }
}

该模块导出一个 javascript 对象,{connection: ..., tableName: ..., ...}。 Sails 使用该值来扩展 Waterline 模型对象。

实现相同功能的 TypeScript 代码是什么?我尝试了几种变体,但似乎没有得到它。帮助!谢谢。

最佳答案

var objectToExport = {
  connection: 'freshairMysqlServer', ... };
export = objectToExport;

并确保使用--module commonjs进行编译

关于node.js - 导出模块值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27946836/

相关文章:

node.js - 修复 npm 全局包符号链接(symbolic link)

javascript - Socket.io 无法访问模块

node.js - Sendgrid 中的替代代币列表

typescript - 使用扩展运算符在 TypeScript 中查找可空数字数组的最大值

angular - patchValue with { emitEvent : false, onlySelf: true } 在 Angular 中触发 valueChanges

validation - Sails.js 和水线 : dynamic validation by DB request

javascript - 在 beforeCreate 中访问 req.headers

javascript - 禁用仅在生产环境 sails js 中运行的 Grunt 任务?

javascript - 我无法返回 axios 请求的响应

angular - NgModule 嵌套 forRoot