Reputation: 381
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.
Upvotes: 0
Views: 694
Reputation: 41
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 [email protected]
Upvotes: 0
Reputation: 25860
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
Upvotes: 1