0
我正在做一個React,Express,Massivejs,postgreSql應用程序。我收到錯誤「TypeError:db.createList不是一個函數」任何時候我試圖打我的職位端點。我不確定如何補救它,因爲它看起來正確。獲取「TypeError:db.createList不是函數」
我的文件結構:
我的服務器上的文件看起來是這樣的:
var express = require('express');
var bodyParser = require('body-parser');
var cors = require('cors');
var massive = require("massive");
var connectionString = 'postgress://[email protected]localhost/todo';
var massiveInstance = massive.connectSync({connectionString : connectionString})
var config = require('./config.js');
var app = module.exports = express();
app.set('db', massiveInstance);
var listCtrl = require('./controller/listCtrl.js');
// **************** Middleware ****************
app.use(express.static(__dirname + './../public'));
app.use(bodyParser.json());
// ****************** Endpoints ***************
app.post('/api/add/list', listCtrl.createList);
app.get('/api/get/list', listCtrl.createList);
app.get('*', function(req, res) {
res.sendFile('index.html', { root: './public'});
})
app.listen(config.port, function() { console.log('Server initiated on port', config.port); });
我的控制器看起來是這樣的:
var app = require('../server.js');
var db = app.get('db');
module.exports = {
createList: function(req, res, next) {
console.log('db'my);
db.createList([req.body.name], function(err, res) {
res.status(200).send('List created');
})
},
readList: function(req, res) {
db.readList(function(err, res) {
if (err) {
console.log("readList failed");
} else {
console.log("readList working " + req.body, req.params);
}
})
}
}
我createList.sql文件看起來像這樣:
INSERT INTO list (
name
)
VALUES (
$1
);
您是否將文件命名爲「createlist.sql」或「createList.sql」? –
錯誤的圖片抱歉。但我把它命名爲createList.sql。 –