我正在尝试使用 mass.js 连接到 postgres 数据库。我现在在 postgress 中使用命令行创建了一个数据库和一个表,当我尝试使用 Massive.js 将其连接到 postgres 时出现错误。在我看来,我在 require('massive') 中遇到了错误。但是我已经在 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)
这是我的代码:
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);
});
帮助将不胜感激。