简体   繁体   中英

Not able to connect to postgres using Massive.js

I am trying to connect to postgres database using massive.js. I have created a database and a table using command line in postgress now when I am trying to connect it to postgres using Massive.js I am getting error. To me it looks like I am getting error in require('massive'). But I have already installed massive in nodemodules.

 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)

Here is my code :

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);
});

Help would be really appreciated.

Old Node.js version, with 6.x required as the minimum, as per its travis.yml :

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

Try using Massive.ConnectSync(ConnectionString : yourConnectionString); Example: var db=Massive.ConnectSync(ConnectionString : yourConnectionString); Use the instance db for getting the data from Database.

For more info drop a mail to d.krishnaprasad2010@gmail.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM