无法使用 Massive.js 连接到 postgres



我正在尝试使用massive.js连接到postgres数据库。现在,当我尝试使用 Massive 将其连接到 postgres 时,我已经在 postgress 中使用命令行创建了一个数据库和一个表.js我收到错误。对我来说,看起来我在 require('massive'( 中遇到了错误。但是我已经在节点模块中安装了大量。

 exports = module.exports = (connection, loaderConfig = {}, driverConfig = {}) => {
                                                     ^
SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/shoppertreat/postgres/index.js:3:17)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)

这是我的代码:

const express = require('express');
const http = require('http');
const massive = require('massive');
const app = express();
massive({
  host: '127.0.0.1',
  port: 5432,
  database: 'demo',
  user: 'postgres',
  password: ''
}).then(instance => {
  app.set('db', instance);
  app.get('/', (req, res) => {
    req.app.get('db').feed_items.find({
      'rating >': 0
    }, {
      order: 'created_at desc'
    }).then(items => {
      res.json(items);
    });
  });
  http.createServer(app).listen(3000);
});

帮助将不胜感激。

Old Node.js 版本,根据其 travis.yml 至少需要 6.x:

language: node_js
node_js:
  - '7'
  - '6'
addons:
  postgresql: "9.5"
services:
  - postgresql
before_script:
  - psql -c 'create database massive;' -U postgres
after_success:
  - npm run coverage

尝试使用 Massive.ConnectSync(ConnectionString : yourConnectionString); 示例:var db=Massive.ConnectSync(ConnectionString : yourConnectionString); 使用实例数据库从数据库获取数据。

欲了解更多信息,请发送电子邮件至 d.krishnaprasad2010@gmail.com

最新更新